简体   繁体   中英

java.util.zip.ZipException: invalid CEN header (bad signature)

I'm getting this error when doing this (relatively simple) piece of code:

    ZipFile zf = new ZipFile(fn);
    Enumeration<? extends ZipEntry> eze = zf.entries();
    while (eze.hasMoreElements()) {
        ZipEntry ze = eze.nextElement();
        System.out.println(ze.getName());
    }
    zf.close();

Actually. Interestingly enough, I get it on java-sun-6u32 and java-1.6.0-openjdk-amd64, but java-sun-7u4 succeeds. unzip itself seems to handle it fine. I'm guessing that means that these zipfiles are perhaps created by some newer version of zip that java 7 understands, but that previous versions do not. But, any insight would be appreciated. Also, since in production I don't really have the option of using java 7, any way of making earlier versions of java understand this new version of zip (if that in fact is what the problem is, of course.)

Thanks!

7z l -slt output provided in your comment is quite useful:

Type = zip 64-bit

gives a hint, that it's ZIP64 (version 4.5 of ZIP specification). However, though Java7 supports it, this support is not backported to Java6 at the moment and you will have to resort to external library such as Apache Compress .

PS For reference, file test.zip would output something like

test.zip: Zip archive data, at least v4.5 to extract

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM