/**
*
* Function:解压缩
* @param directory 解压到的路径
* @param zip 需解压缩的zip包
* @return boolean
* @author
*/
private boolean unzipFile(String directory, File zip) throws Exception{
ZipFile zipFile = new ZipFile(zip,Charset.forName("gbk"));
Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zipFile.entries();
ZipEntry entry;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
while (entries.hasMoreElements()) {
entry = entries.nextElement();
if(!entry.isDirectory()){
bis=new BufferedInputStream(zipFile.getInputStream(entry));
//解压缩里,去除最外层的文件夹
String entryName = entry.getName().substring(entry.getName().indexOf("/")+1);
File file=new File(directory,entryName);
if(!file.exists()){
(new File(file.getParent())).mkdirs();
}
bos=new BufferedOutputStream(new FileOutputStream(file));
int b;
while((b=bis.read())!=-1){
bos.write(b);
}
bos.close();
bis.close();
System.out.println(file+"解压成功");
}
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
解压缩文件到指定路径(包含中文)
最新推荐文章于 2021-08-31 14:49:37 发布