I get the exception
java.util.zip.ZipException: invalid distances set at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:165) at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:195) at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107)
when I want to unzip a file that I have copied before with
FileUtils.copyFile(File srcFile, File destFile)
(org.apache.commons.io).
If I don’t copy the file and use the original zip file, the unzipping works just fine.
I have also used a different file-copy API from google guava. But the error is the same when I want to unzip the file.
The file I want to copy and unzip is a large file: its an adopt-open-jdk zip file.
I don’t think it is an error in the unzipping logic. It is more related to what the copy does to the file such that it can’t be unzipped correctly.
I use the following sample code for unzipping: https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java
Edit: the copied file does not become corrupt. The file size is identical with the original and I can open the copied zip with 7zip with no errors. Content is complete.
Advertisement
Answer
I found the error myself. The previous maven build process copied the zip-file incorrectly and incompletely into a target jar file instead of inside the target folder directly. After that, I was accessing that file via classloader and the fileutils.copy copied an already incorrectly stored zip.
My bad, I did compare the wrong files when writing they were identical.