java.util.zip.ZipError:无效的 CEN 标头(错误的签名)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22536279/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:19:41  来源:igfitidea点击:

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

javazipnio

提问by Justin Kredible

I'm using Java 1.7.0_40 on Red Hat Linux and I have the following code:

我在 Red Hat Linux 上使用 Java 1.7.0_40,我有以下代码:

Path zipfile = Paths.get(filename);
FileSystem fs = FileSystems.newFileSystem(zipfile, FileTest.class.getClassLoader());

The filenamevariable points to a zip file that is 788MB. The uncompressed size of the zip file is 8.3GB. When I run the code above I get the following exception:

filename变量指向一个 788MB 的 zip 文件。zip 文件的未压缩大小为 8.3GB。当我运行上面的代码时,出现以下异常:

Exception in thread "main" java.util.zip.ZipError: invalid CEN header (bad signature)
        at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605)
        at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1058)
        at com.sun.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:130)
        at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:139)
        at java.nio.file.FileSystems.newFileSystem(FileSystems.java:386)
        at FileTest.readFromZip(FileTest.java:35)
        at FileTest.main(FileTest.java:25)

I was under the impression that Java 7 was capable of handling large zip files. Can anyone explain why this is happening?

我的印象是 Java 7 能够处理大型 zip 文件。谁能解释为什么会这样?

Thanks.

谢谢。

回答by Stephen C

There are two possible explanations:

有两种可能的解释:

回答by Puneet Pandey

I too faced the issue in Maven based project. The issue occurred because of corrupted jars. Deleted the jars from .m2 folder and built the project again; and it worked like charm.

我在基于 Maven 的项目中也遇到了这个问题。出现此问题是由于 jar 损坏。从 .m2 文件夹中删除 jars 并重新构建项目;它的作用就像魅力一样。

回答by Thangadurai

This problem occurs Due to jar file was downloaded is corrupted.

出现此问题是由于下载的 jar 文件已损坏。

if you are using Maven.

如果您使用的是 Maven。

  • For Solving this issue, Delete Particular Jar File in C:/Users/public/.m2/repositoryfolder.
  • After that add New Version of Maven in POM.xml.
  • Rebuild and try. It will work fine.
  • 要解决此问题,请删除C:/Users/public/.m2/repository文件夹中的特定 Jar 文件。
  • 之后在POM.xml中添加新版本的 Maven 。
  • 重建并尝试。它会正常工作。

回答by harvyS

It is problem of configuration for maven compiler in your pom file. Default version java source and target is 1.5, even used JDK has higher version.

这是你的 pom 文件中 maven 编译器的配置问题。默认版本 java 源和目标是 1.5,即使使用的 JDK 也有更高的版本。

To fix, add maven compiler plugin configuration section with higher java version, example:

要修复,请添加具有更高 Java 版本的 Maven 编译器插件配置部分,例如:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.6.1</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

For more info check these links:

有关更多信息,请查看以下链接:

maven compiler

Maven 编译器

bug report

错误报告

回答by vallismortis

Large file (4GB+) support for zip archives (i.e. 64-bit zip support) was addressed by issue JDK-4681995("Add support for large (> 4GB) zip/jar files").

问题JDK-4681995“添加对大(> 4GB)zip/jar 文件的支持”)解决了对 zip 存档的大文件 (4GB+) 支持(即 64 位 zip 支持)。

However, this change was not included in Java 7 until 1.7.0 build 55, which was a few builds after the specific version (1.7.0 build 40) that you were using. Updating to build 55 or later would solve the problem.

但是,此更改直到 1.7.0 build 55 才包含在 Java 7 中,这是您使用的特定版本 (1.7.0 build 40) 之后的几个版本。更新到 build 55 或更高版本将解决该问题。