Java.util.zip.ZipException: error opening zip file

I have a Jar file that contains other nested Jars. When I call the new JarFile() constructor in this file, I get an exception that says:

java.util.zip.ZipException: error opening zip file

When I manually unzip the contents of this Jar file and zip it again, it works fine. Also note that this exception is visible only in versions of WebSphere 6.1.0.7 and later. The same thing works fine with tomcat and WebLogic. Also, when I use a JarInputStream instead of a JarFile, I can read the contents of the Jar file without any exception. Please let me know if you have ideas on how to fix this.

Thanks Sandhya

+48
java unzip zip
Nov 28 '08 at 7:12
source share
11 answers

Make sure your jar file is not corrupted. If it is damaged or cannot unpack, this error will occur.

+18
Sep 27 '10 at 7:14
source share
— -

I ran into the same problem. I had a zip archive that java.util.zip.ZipFile could not process, but WinRar unpacked it just fine. I found an article on SDN about compression and decompression options in Java. I slightly modified one of the code examples to create a method that could finally process the archive. Trick uses a ZipInputStream instead of a ZipFile and in sequentially reading a zip archive. This method is also capable of handling an empty mail archive. I believe that you can customize the method to suit your needs, since all zip classes have equivalent subclasses for .jar archives.

 public void unzipFileIntoDirectory(File archive, File destinationDir) throws Exception { final int BUFFER_SIZE = 1024; BufferedOutputStream dest = null; FileInputStream fis = new FileInputStream(archive); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry; File destFile; while ((entry = zis.getNextEntry()) != null) { destFile = FilesystemUtils.combineFileNames(destinationDir, entry.getName()); if (entry.isDirectory()) { destFile.mkdirs(); continue; } else { int count; byte data[] = new byte[BUFFER_SIZE]; destFile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, BUFFER_SIZE); while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); fos.close(); } } zis.close(); fis.close(); } 
+12
Sep 22 2018-11-11T00:
source share

It may be associated with log4j.

Do you have the log4j.jar file in the path of the Java Java class (as defined in the startup file), as well as the path to the application class?

If you make sure that the log4j.jar file is in the path of the java class and that it is NOT in the web-inf / lib directory of your web application.




It can also be associated with ant version (maybe this is not your case, but I put it here for reference):

You have a .class file in your class path (i.e. not a directory or a .jar file). Starting with ant 1.6, ant will open the files in class validation for manifest entries. This attempt to open will fail with the error "java.util.zip.ZipException"

The problem does not exist with ant 1.5, since it does not try to open files. - so make sure your classpath does not contain .class files.




On the other hand, did you consider individual banks ?
You can in the manifest of your main jar, refer to other jars with this attribute:

 Class-Path: one.jar two.jar three.jar 

Then put all your jars in one folder.
Again, it may be invalid for your case, but still there for reference.

+10
Nov 28 '08 at 7:16
source share

I saw this exception before the JVM considers temp to be unavailable due to the lack or absence of write permission.

+8
Nov 28 '08 at 17:50
source share

I solved this by clearing jboss-xyz / server [config] / tmp and jboss-xyz / server / [config] / working directories.

+3
Feb 08 2018-11-18T00:
source share

I also see this error when I am absent on disk in the file system to which she writes. That way you can either give it more space, clear the log files, etc.

+2
Sep 23 '14 at 19:03
source share

I saw this with a specific Zip file with Java 6, but it left when I switched to Java 8 (I did not test Java 7), so it seems that newer versions of ZipFile in Java support more compression algorithms and therefore can read files. which do not work with earlier versions.

+1
Apr 23 '15 at 19:44
source share

I ran into these problems due to corrupted ZIP Fils

Check if your JAR file has been uploaded. Completely

+1
Mar 23 '17 at 4:55 on
source share

Liquibase was getting this error for me. I solved this after I debugged and watched as Liquibase tried to load the libraries and found that it was an error in the manifest files for commons-codec-1.6.jar. In fact, there is either a damaged zip file somewhere in your path, or an incompatible version is used. When I explored the Maven repository for this library, I found that newer versions appeared and a new version was added in pom.xml. On this I was able to continue.

0
Jun 09 '15 at 14:10
source share

Maybe the zip file is damaged or thrown at boot.

0
Mar 22 '17 at 7:24
source share

I get an exception

 java.util.zip.ZipException: invalid entry CRC (expected 0x0 but got 0xdeadface) at java.util.zip.ZipInputStream.read(ZipInputStream.java:221) at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:140) at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:118) ... 

when unpacking the archive in Java. The archive itself did not look corrupted, since 7zip (and others) opened it without any problems or complaints about an invalid CRC.

I switched to Apache Commons Compress to read zip records and solved the problem.

0
Mar 30 '17 at 12:32
source share



All Articles