//解压文件
@SuppressWarnings("unchecked")
public void unzip(File cosFile,long orgId,long categoryId,long userPkId,String userName) throws Exception{
ZipFile zFile = new ZipFile(cosFile);//要解压的文件(绝对路径)
zFile.setFileNameCharset("UTF8");
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
String dest=System.getProperty("java.io.tmpdir"); //获取系统临时目录(文件解压存放的目录)
List<FileHeader> list = zFile.getFileHeaders();
for (FileHeader fh : list) {
String fileName = fh.getFileName();
if(fileName.equals("Project.xml")){
zFile.extractFile(fileName, dest);//根据指定的文件名解压
//zFile.extractAll(dest);//解压全部
File file = new File(dest+fileName);//获得解压的文件
standardBillService.analyzeXMLByProject(file, orgId, categoryId, userPkId, userName);
//用完马上直接删除
file.delete();
break;
}
}
}