If you want to extract zip file created by other software.
The charset of file name might be system default charset (such as GBK, Shift-JIS or others charsets...)
In this case, if one of source file name contain a unicode char which does not exist in that charset.
The file name in that ZipEntry is convered to UTF-8.
To extract this kind of zip file, the file name must be converted by custom code one by one.
ZipFile zipFile = new ZipFile("input.zip");
UnzipParameters param = new UnzipParameters();
zipFile.setFileNameCharset("ISO8859-1");
List list = zipFile.getFileHeaders();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
FileHeader fh = (FileHeader) iterator.next();
byte[] b = fh.getFileName().getBytes("ISO8859-1");
String fname = null;
try {
fname = new String(b, "UTF-8");
if (fname.getBytes("UTF-8").length != b.length) {
fname = new String(b,"GBK");//most possible charset
}
} catch (Throwable e) {
//try other charset or ...
System.err.println("Invalid file name: "+fname);
}
z.extractFile(fh, dir, param, fname);
}