簡體   English   中英

將Blob提取到文件:某些文件缺少數據

[英]Extracting blobs to files: some files are missing data

我正在嘗試從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());
                    }
                }
//...

嘗試添加fos.flush(); fos.close();之前fos.close(); 看看是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM