public String unzipSourceCsvZipFile(String[] unzipFolderArrInPath, String sourceCsvZipFilePath) throws Exception {
String targetFolderRealPath = FilesUtil.createFolderPath(unzipFolderArrInPath);
ZipFile zipFile = new ZipFile(sourceCsvZipFilePath);
Enumeration entries = zipFile.entries();
OutputStream fosUserCsv = null;
InputStream fisZipCsv = null;
try {
for (; entries.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String zipEntryName = entry.getName();
if (entry.isDirectory()) {
continue;
} else if (!zipEntryName.contains(CSV_FILE_EXTENTION)) {
continue;
}
String sourceCsvPath = targetFolderRealPath + File.separator + zipEntryName;
fosUserCsv = new FileOutputStream(sourceCsvPath);
fisZipCsv = zipFile.getInputStream(entry);
byte[] buf1 = new byte[1024];
int len;
while ((len = fisZipCsv.read(buf1)) > 0) {
fosUserCsv.write(buf1, 0, len);
}
fosUserCsv.close();
fisZipCsv.close();
}
return targetFolderRealPath;
} finally {
if (fosUserCsv != null) {
fosUserCsv.close();
}
if (fisZipCsv != null) {
fisZipCsv.close();
}
zipFile.close();
}
}
Java解压Zip文件(Java unzip file)
最新推荐文章于 2024-07-19 11:21:53 发布