Very large zip file (> 50GB) --> ZipException: invalid CEN header

被刻印的时光 ゝ 提交于 2020-01-03 08:23:13

问题


I'm trying to open a ZIP file in JAVA.

The code below works fine except with some large files in which case I get the following exception:

Exception in thread "main" java.util.zip.ZipException: invalid CEN header (bad signature)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.zip.ZipFile.<init>(ZipFile.java:75)

Is there a known bug? Can it be due to higher compression level not supported in JAVA?

Note that I can not use Winzip to uncompress the file, and gzip under Linux gives an error about the data-length (uncompressed file is around 80 GB). I had to use the following workaround to uncompress it:

gunzip -S .zip < file.zip > file

Any ideas would be very very helpful.

Code:

if (file.getExtension().equals("gz")) {
  br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(name))));
}
else if (file.getExtension().equals("zip")) {
    ZipFile zipFile = new ZipFile(name); // <-------------------FAILS HERE
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry zipEntry = entries.nextElement();
        System.out.println("ZIP File in the archive:" + zipEntry.getName());
        br = new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry)));
        break;
    }
}

回答1:


If you are not using Java 7 (which support ZIP64), the issue may be that java is trying to use the old ZIP format



来源:https://stackoverflow.com/questions/10096289/very-large-zip-file-50gb-zipexception-invalid-cen-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!