解压缩由truezip创建的存档时出错,其中包含大于2 GB的文件

时间:2011-09-21 11:23:04

标签: java zip truezip

我使用java.util.zip存档文件,直到我遇到大尺寸文件(> 2 GB)的问题。我尝试切换到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.
    }

0 个答案:

没有答案