读取 ZIP 文件会给出“无效的 LOC 标头”例外
我有一个很大的 zip 文件,4.3G。它包含大约 100k 条目。 我在 Linux、Ubuntu 32 位上使用 Java 1.6.0_14 阅读它,并得到以下异常。
java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method)
at java.util.zip.ZipFile.access$1200(ZipFile.java:29)
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:447)
at java.util.zip.ZipFile$1.fill(ZipFile.java:230)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
我对任何其他 ZIP 文件没有任何问题(处理它们的代码非常成熟),并且我已经验证我可以使用“unzip”从命令行正确解压缩 zip 文件。
有什么线索吗?谢谢!
I have a large zip file, 4.3G. It contains about 100k entries.
I am reading it using Java 1.6.0_14 on Linux, Ubuntu 32 bit, and get the following exception.
java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method)
at java.util.zip.ZipFile.access$1200(ZipFile.java:29)
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:447)
at java.util.zip.ZipFile$1.fill(ZipFile.java:230)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
I don't have issues with any other ZIP files (the code to process them is pretty mature) and I have verified that I can correctly unzip the zip file from the command line using 'unzip'.
Any clues? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大小超过 4GB 的 Zip 文件需要 Zip 文件阅读器支持 PKWARE 的 ZIP64 扩展。
在 Java 6 之前,java.util.zip 类中还没有这种支持,最近才添加到 Java 7 中(不用说,在撰写本文时,这还不是 GA 版本)。
参考:
Zip files greater than 4GB in size, require the zip file reader to support the ZIP64 extensions by PKWARE.
Until Java 6, this support is not available in the java.util.zip classes, and has only been recently added into Java 7 (needless to say, that this is not a GA release, at the time of writing this).
Reference:
正如其他人提到的,文件 > ZIP 标准不支持 4GB。有一个名为 ZIP64 的扩展可以解决此问题,但它不会在 Java 7 之前就支持。
有很多库支持 ZIP64,但是当我上次检查时,它们都不支持流,而是依赖于文件。如果这不困扰您,TrueZip 可能会工作得很好。
如果您正在处理流,则必须使用临时文件。
As others mentioned, files > 4GB are not supported by the ZIP standard. There's an extension called ZIP64 that adresses this issue, but it won't be supported before Java 7.
There are a number of libraries that support ZIP64, but when I last checked none of them supported streams, but relied on files instead. If that doesn't bother you, TrueZip might work fine.
If you're dealing with streams, you'll have to use temporary files.