0

大きなサイズのファイル (> 2 GB) で問題が発生するまで、java.util.zip を使用してファイルをアーカイブしていました。truezipに切り替えてみました。ファイルを正常にアーカイブできましたが、抽出中に「ファイルは CRC チェックに失敗しました」というエラーが表示されます。ファイルをアーカイブするために使用されるコードは次のとおりです。

int BUFF_MAX_SIZE = 524288;
    byte[] buf = new byte[BUFF_MAX_SIZE];
    long time;
    long size;
    File fp;
    String[] filenames = {"D:\\abc", "D:\\large file", "D:\\xyz"};
    int n = filenames.length;
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream("archive.zip")), Charset.forName("UTF-8"));
    for (int i = 0; i < n; i++) {
        fp = new File(filenames[i]);
        time = fp.lastModified();
        size = fp.length();            
        try {
            TFileInputStream in = new TFileInputStream(filenames[i]);
            ZipEntry ze = new ZipEntry(filenames[i]);
            ze.setTime(time);
            ze.setSize(size);
            out.putNextEntry(ze);
            TFile.getDefaultArchiveDetector();
            int len = 0;
            collectCnt = 0;
            while ((len = in.read(buf, 0, BUFF_MAX_SIZE)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.closeEntry();

        } catch (Exception ex) {
            //
        }
    }
    try{
        out.close();
    } catch (Exception ex){
        // error closing outout stream.
    }
4

0 に答える 0