JAVA zip decompress MALFORMED error, zipmalformed

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.