JAVA zip decompress MALFORMED error, zipmalformed
Some files may report exceptions when you decompress the files using JDK or later.
Exception in thread "main" java.lang.IllegalArgumentException: MALFORMED at java.util.zip.ZipCoder.toString(ZipCoder.java:58) at java.util.zip.ZipFile.getZipEntry(ZipFile.java:567) at java.util.zip.ZipFile.access$900(ZipFile.java:61) at java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:525) at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:500) at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:481) at zip.ReadingArchive.unzip(ReadingArchive.java:36) at zip.ReadingArchive.unzip(ReadingArchive.java:82) at zip.ReadingArchive.unzip(ReadingArchive.java:82) at main.Main.main(Main.java:13)
The reason is because the file name is caused by Chinese characters, and ZIPFile uses the UTF-8 by default, in the case of decompression non-UTF-8 will report an error
Public ZipFile (File file, int mode) throws IOException {
This (file, mode, StandardCharsets. UTF_8 );
}
The final solution I used is
Charset gbk = Charset. forName ("GBK ");
ZipFile zipFile = new ZipFile (zipFileName, gbk );
Of course, this certainly does not apply to all environments. You can use the Modified Character Set for reference only.