Java Extract zip Java.lang.IllegalArgumentException:MALFORMED error

Source: Internet
Author: User

The ZIP compression package encountered an error during the decompression process, prompting the following

Java.lang.IllegalArgumentException:MALFORMED at  
    java.util.zip.ZipCoder.toString (Unknown Source)  
    at Java.util.zip.ZipInputStream.readLOC (Unknown Source) at  
    java.util.zip.ZipInputStream.getNextEntry (Unknown Source) at  
    com.yc.utils.TestZip.extZipFileList (testzip.java:40) at  
    Com.yc.utils.TestZip.main ( TESTZIP.JAVA:21)  

Look up the information on the Internet, there is a saying is the problem of coding, see how the Foreigner said, reference, is really the problem of coding. Attach my partial uncompressed code

public static void Unzip (string zipfilepath, String TargetPath) throws IOException {OutputStream OS =
        Null
        InputStream is = null;
        ZipFile zipfile = null;
            try {zipfile = new ZipFile (Zipfilepath,charset.forname ("GBK"));
            String directorypath = ""; if (null = = TargetPath | | "". Equals (TargetPath)) {directorypath = zipfilepath.substring (0, Zipfilepath. Las
            Tindexof ("."));
            else {directorypath = TargetPath;
            } enumeration<?> Entryenum = Zipfile.entries ();
                if (null!= entryenum) {zipentry zipentry = null;
                    while (Entryenum.hasmoreelements ()) {ZipEntry = (zipentry) entryenum.nextelement (); if (zipentry.getsize () > 0) {//files file TargetFile = Fileutil.buil
       Dfile (DirectoryPath                         + File.separator + zipentry.getname (), false);
                        OS = new Bufferedoutputstream (new FileOutputStream (targetfile));
                        is = Zipfile.getinputstream (zipentry);
                        byte[] buffer = new byte[4096];
                        int readlen = 0;
                            while ((Readlen = is.read (buffer, 0, 4096)) >= 0) {os.write (buffer, 0, Readlen);
                        Os.flush ();
                        } is.close ();
                    Os.close (); } if (Zipentry.isdirectory ()) {String pathtemp = DirectoryPath + File.separato
                    	R + zipentry.getname ();
                    	File File = new file (pathtemp);
                        File.mkdirs ();
System.out.println (pathtemp);
                    Continue
     }           The catch (IOException ex) {throw ex;
                finally {if (null!= zipfile) {zipfile.close ();
            ZipFile = null;
            } if (null!= is) {is.close ();
            } if (null!= OS) {os.close (); }
        }
    }


Statement:
ZipFile = new ZipFile (Zipfilepath,charset.forname ("GBK"));
Not all compression packages are encoded GBK, and special handling is required for different situations.

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.