ZIP文件解压缩
程序员文章站
2022-05-15 10:59:01
...
public void unZip(File file, String unzipFolder) throws IOException {
byte b[] = new byte[2048];
int length;
ZipFile zipFile = new ZipFile(file, "MS932");
@SuppressWarnings("rawtypes")
Enumeration enumeration = zipFile.getEntries();
ZipEntry zipEntry = null;
OutputStream outputStream = null;
InputStream inputStream = null;
while (enumeration.hasMoreElements()) {
zipEntry = (ZipEntry) enumeration.nextElement();
File loadFile = new File(unzipFolder + zipEntry.getName());
if (zipEntry.isDirectory()) {
loadFile.mkdirs();
} else {
if (!loadFile.getParentFile().exists())
loadFile.getParentFile().mkdirs();
outputStream = new FileOutputStream(loadFile);
inputStream = zipFile.getInputStream(zipEntry);
/* 写入文件 */
while ((length = inputStream.read(b)) > 0) {
outputStream.write(b, 0, length);
}
}
}
outputStream.close();
inputStream.close();
zipFile.close();
}
上一篇: js实现获取当前日期后几天的日期
下一篇: 解压缩文件