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.