0

I was using java.util.zip to archive files until I encountered problems for large size files (> 2 GB). I tried switching to truezip. I was able to successfully archive the files but while extracting I get 'File fails CRC check' error. Here is the code used to archive the files.

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.
    }
  • There's been a series of bugs in JDK's handling of ZIP files >2GB. Most (all?) have been fixed. What's the exact version of your JDK? – NPE Sep 21 '11 at 13:19
  • What are your import statements and why are you mixing APIs like this? It isn't clear if you are using java.util.zip or de.schlichtherle.truezip.zip here and if you are using TrueZIP, then you should solely use the TrueZIP File* API. Also, if you are using TrueZIP, then you should make sure to use the latest version, which is TrueZIP 7.3.2. – Christian Schlichtherle Sep 22 '11 at 00:07
  • I am using the latest true zip (version 7.3.2). I am not using java.util.zip but only de.schlichtherle.truezip.* – Madhusudan Sep 22 '11 at 04:37
  • I am currently using jdk 1.6.0_20 – Madhusudan Sep 22 '11 at 05:01
  • I modified my code a bit and created a simple extraction application. Now it works fine. – Madhusudan Oct 14 '11 at 05:01
  • Madhusudan: can you please post an answer to the question yourself and then accept that answer so that we can close this question? Also, you need to accept answers to previous questions if they fix your problem. – Zecas May 23 '12 at 10:23
  • I overcame the issue my custom splitting the files on the fly before archiving large files and creating multiple archive files. I also created custom extractor accordingly. – Madhusudan May 31 '12 at 05:26

0 Answers0