zip压缩文件解压乱码问题,请使用commons.compress 的jar处理
样例代码如下:
public static List> getUnZip(File srcFile, File destDir) throws IOException {
int BUFFER_SIZE = 2048;
ZipArchiveInputStream is = null;
List> lst_unzip = new ArrayList>();
try {
is = new ZipArchiveInputStream(new BufferedInputStream(new FileInputStream(srcFile), BUFFER_SIZE));
ZipArchiveEntry entry = null;
while ((entry = is.getNextZipEntry()) != null) {
if (entry.isDirectory()) {
File directory = new File(destDir, entry.getName());
directory.mkdirs();
} else {
Map unfile = new HashMap();
unfile.put("src", "");
unfile.put("yname", "");
String subffix = entry.getName();
String fname = destDir + subffix;
OutputStream os = null;
try {
unfile.put("yname", entry.getName());
os = new BufferedOutputStream(new FileOutputStream(new File(fname)), BUFFER_SIZE);
IOUtils.copy(is, os);
} finally {
IOUtils.closeQuietly(os);
}
subffix = fname;
if (subffix.indexOf(".") > 0) {
subffix = subffix.substring(subffix.lastIndexOf(".") + 1);
}
String nfname = destDir + UUID.randomUUID().toString() + "."+ subffix;
File f = new File(fname);
File toFile = new File(nfname);
FileUtils.copyFile(f,toFile);
if(f.exists())
{
f.delete();
}
unfile.put("src", toFile.getName());
unfile.put("yname", entry.getName());
lst_unzip.add(unfile);
}
}
}finally{
IOUtils.closeQuietly(is);
}
return lst_unzip;
}
public static List> getUnZip(String srcFile, String destDir) throws IOException {
File zip = new File(srcFile);
if (!zip.exists()) {
return new ArrayList>();
}
File dir = new File(destDir);
if ((!dir.exists()) || (!dir.isDirectory())) {
dir.delete();
dir.mkdirs();
}
if (!destDir.endsWith("//") && !destDir.endsWith("/")) {
destDir += "//";
}
return getUnZip(new File(srcFile), new File(destDir));
}