JAVAZipFile解压缩zip避免字段名中文编码
原创String zipFilePath="C:\Users\Joue\Desktop\unzip.zip";
String destDir ="C:\Users\Joue\Desktop\unzip";
ZipFile zipFile = new ZipFile(zipFilePath); //此处可自动识别代码
Enumeration<?> emu = zipFile.getEntries();
BufferedInputStream bis;
FileOutputStream fos;
BufferedOutputStream bos;
File file, parentFile;
ZipEntry entry;
byte[] cache = new byte[CACHE_SIZE];
while (emu.hasMoreElements()) {
entry = (ZipEntry) emu.nextElement();
if (entry.isDirectory()) {
File entryFile = new File(destDir + entry.getName());
if (!entryFile.exists() && !entryFile.mkdirs()) {
throw new Exception("无法创建文件夹");
}
continue;
}
bis = new BufferedInputStream(zipFile.getInputStream(entry));
file = new File(destDir + entry.getName());
parentFile = file.getParentFile();
if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs()) {
throw new Exception("文件夹创建失败");
}
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos,1024);
int nRead;
while ((nRead = bis.read(cache, 0, 1024)) != -1) {
fos.write(cache, 0, nRead);
}
bos.flush();
IOUtils.closeQuietly(bos);
IOUtils.closeQuietly(fos);
IOUtils.closeQuietly(bis);
}
zipFile.close();
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除