/**
* @Description 解析zip包
* @param srcFile zip包的地址
* @param desDirectory 解析文件夹地址
* @throws IOException
*/
public void getFile(String srcFile, String desDirectory){
try {
File file = new File(srcFile);
Charset charset = Charset.forName(“GBK”);
ZipInputStream zis = new ZipInputStream(new FileInputStream(file ), charset);
ZipEntry entry = null;
File pathFile = new File(desDirectory);
if (!pathFile.exists()) {
pathFile.mkdirs();
}
BufferedOutputStream bos = null;
while ((entry = zis.getNextEntry()) != null) {
String outPath = desDirectory + entry.getName();
outPath = outPath.replace(“/”, File.separator);
File file = new File(outPath.substring(0, outPath.lastIndexOf(File.separator)));
if (!file.exists()) {
file.mkdirs();
}
// 判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if (new File(outPath).isDirectory()) {
continue;
}
FileOutputStream fos = new FileOutputStream(desDirectory + entry.getName());
bos = new BufferedOutputStream(fos);
byte[] buf = new byte[10 * 1024 * 1024];
int len;
while ((len = zis.read(buf)) != -1) {
bos.write(buf, 0, len);
}
zis.closeEntry();
bos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
java解析zip包(9G)的代码
于 2022-09-22 16:47:50 首次发布