Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

zip

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!

like image 276
bnsh Avatar asked Sep 10 '12 06:09

bnsh


1 Answers

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.

P.S. For reference, file test.zip would output something like

test.zip: Zip archive data, at least v4.5 to extract
like image 53
barti_ddu Avatar answered Oct 13 '22 16:10

barti_ddu