我正在尝试从 oracle 数据库中提取 TIF 文件。从 blob 转换的大多数文件都可以正常工作,但有些文件似乎丢失了几千字节。
例如,当我使用 SQL GUI 提取文件时,我得到一个大小为 912,390 字节的 TIF 文件。当我使用我的方法时,我得到一个大小为 909,312 字节的文件。缺少的 3078 字节意味着我无法打开文件。我在做什么导致文件不完整?
//...
if ((FileOutDir != null) && (blobSQL != null) && (conn != null)) {
PreparedStatement selBlobs = null;
OutputStream fos = null;
if (conn != null) {
if (blobSQL != null) {
try {
selBlobs = conn.prepareStatement(blobSQL);
ResultSet rs = selBlobs.executeQuery();
Blob blob = null;
InputStream is = null;
int b = 0;
int cols = rs.getMetaData().getColumnCount();
String filepath = FileOutDir;
while (rs.next()) {
blob = rs.getBlob(1);
is = blob.getBinaryStream();
filepath += "/";
for (int c = 2; c <= cols; c++) {
filepath += rs.getObject(c).toString() + "_";
}
filepath = filepath.substring(0,
filepath.length() - 1);
filepath += fileSuffix;
fos = new BufferedOutputStream(new FileOutputStream(filepath));
while ((b = is.read()) != -1) {
fos.write(b);
}
filepath = FileOutDir;
b = 0;
}
} catch (Exception e) {
JOptionPane.showMessageDialog(gui, e.toString());
} finally {
try {
selBlobs.close();
fos.close();
} catch (Exception e2) {
System.out
.println("Problem closing BlobToFile connections: "
+ e2.toString());
}
}
//...