1, encountered the problem: in the For loop operation Zip file (the file name contains Chinese), the error is as follows:
Exception in thread "main" Java.lang.IllegalArgumentException:MALFORMEDat java.util.zip.ZipCoder.toString ( zipcoder.java:58) at Java.util.zip.ZipInputStream.readLOC (zipinputstream.java:297) at Java.util.zip.ZipInputStream.getNextEntry (zipinputstream.java:121) at Com.forestfood.FileUntils.done ( fileuntils.java:224) at Com.forestfood.FileUntils.getActionZipFiles (fileuntils.java:196) at Com.forestfood.FileUntils.main (fileuntils.java:24)
2, find the reason: tracking error code line to zipcoder.java:58
Final class zipcoder { string tostring (Byte[] ba, int length) { charsetdecoder cd = decoder (). Reset (); int len = (int) (length * Cd.maxcharsperbyte ()); char[] ca = new char [len]; if (len == 0) return new string (CA); // UTF-8 only for now. Other ArrayDeocder only handles // codingerroraction.replace mode. zipcoder uses // report mode. if (Isutf8 && cd instanceof arraydecoder) { int clen = ((Arraydecoder) CD). Decode (ba, 0 , length, ca); if (Clen  == -1) // malformed throw new illegalargumentexception ("MALFORMED"); return new string (ca, 0 , clen); }
It can be found that if you do not specify the encoding, the default is UTF-8, when decoding the error will occur.
3. Workaround: When creating the ZIP, specify the encoding
FileInputStream FileInputStream = new FileInputStream (Zippath); Charset GBK = Charset.forname ("GBK"); Zipinputstream Zin = new Zipinputstream (FILEINPUTSTREAM,GBK); ZipEntry entry = Zin.getnextentry ();
Java Operation Zip compressed file encountered encoding problem