java 读取 ZIP 文件会出现“无效的 LOC 标头”异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3804505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reading ZIP file gives an 'invalid LOC header' Exception
提问by Joel
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.
我有一个很大的 zip 文件,4.3G。它包含大约 10 万个条目。我正在 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.access00(ZipFile.java:29)
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:447)
at java.util.zip.ZipFile.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'.
我对任何其他 ZIP 文件都没有问题(处理它们的代码非常成熟)并且我已经验证我可以使用“unzip”从命令行正确解压缩 zip 文件。
Any clues? Thanks!
有什么线索吗?谢谢!
回答by Vineet Reynolds
Zip files greater than 4GB in size, require the zip file reader to support the ZIP64 extensions by PKWARE.
大于 4GB 的 Zip 文件需要 zip 文件阅读器支持 PKWARE 的 ZIP64 扩展。
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).
在 Java 6 之前,java.util.zip 类中不提供此支持,并且最近才添加到 Java 7 中(不用说,在撰写本文时,这不是 GA 版本)。
Reference:
参考:
回答by Henning
As others mentioned, files > 4GB are not supported by the ZIP standard. There's an extension called ZIP64that adresses this issue, but it won't be supported before Java 7.
正如其他人提到的,ZIP 标准不支持大于 4GB 的文件。有一个名为ZIP64的扩展可以解决这个问题,但在 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.
有许多库支持 ZIP64,但是当我上次检查时,它们都不支持流,而是依赖于文件。如果这不打扰您,TrueZip 可能会正常工作。
If you're dealing with streams, you'll have to use temporary files.
如果您正在处理流,则必须使用临时文件。