java.util.zip.ZipException:CEN标头无效(签名错误) [英] java.util.zip.ZipException: invalid CEN header (bad signature)

查看:178
本文介绍了java.util.zip.ZipException:CEN标头无效(签名错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行此(相对简单的)代码时遇到此错误:

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();

实际上。有趣的是,我在java-sun-6u32和java-1.6.0-openjdk-amd64上得到它,但java-sun-7u4成功了。解压缩本身似乎处理得很好。我猜这意味着这些zip文件可能是由java 7理解的一些较新版本的zip创建的,但之前的版本没有。但是,任何见解都会受到赞赏。另外,因为在制作中我真的没有选择使用java 7,任何制作早期版本的java的方法都能理解这个新版本的zip(如果实际上 那么问题是什么,当然。)

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.)

谢谢!

推荐答案

7z l -slt 评论中提供的输出非常有用:

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


Type = zip 64-bit

Type = zip 64-bit

给出一个提示,它是 ZIP64 ZIP 规范的4.5版) )。但是,虽然 Java7 支持它,但此支持目前不会向后移植到 Java6 ,您将不得不求助于外部库,例如Apache 压缩

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作为参考, file test.zip 会输出类似

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

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

这篇关于java.util.zip.ZipException:CEN标头无效(签名错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆