Skip to content

Using default UTF-8 charset for uncompressing zip files does not work in all cases.

We have a zip file that current FileUtils.extractZip is not able to handle:

java.lang.IllegalArgumentException: MALFORMED
	at java.util.zip.ZipCoder.toString(ZipCoder.java:58)
	at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:300)
	at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:122)
	at org.simantics.utils.FileUtils.extractZip(FileUtils.java:905)
	at org.simantics.utils.FileUtils.extractZip(FileUtils.java:857)

By visual inspection, the file does not contain any exotic characters. Recompressing the content with 7-Zip or Windows file manager does not help. Accorinding to this https://stackoverflow.com/questions/20013091/java-unzip-error-malformed , using some other charsets could fix the issue.

With the problematic file, using ISO_8859_1 charset allows uncompressing the zip file correctly.

Edited by Marko Luukkainen