JAVA Zip Decompression Malformed error

Source: Internet
Author: User

Recently in the use of Zip decompression, using JDK1.7 and above when extracting, some files will be reported abnormal

ExceptionIn 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: (+) at zip.  Readingarchive.  Unzip(readingarchive.  Java:in main.  Main.  Main(main.  Java:+)              

the reason is because the file name is caused by the Chinese, and zipfile default use of UTF-8, in the case of decompression non-UTF-8 will be error
Public zipfile (file file, int mode) throws IOException {
This (file, mode, standardcharsets.utf_8);
}

Finally I used the solution for
Charset GBK = Charset.forname ("GBK");
ZipFile zipfile = new ZipFile (Zipfilename, GBK);

Of course this certainly does not apply with all environments, you can use the modified character set to resolve, for informational purposes only.

JAVA Zip Decompression Malformed error

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.