//解压压缩文件到指定路径(文本类)
public void unZipFile(){
String zipFilePath = "D:\\通知.zip";
String targerFolder = "D:\\解压文件";
ZipFile zf = null;
try {
zf = new ZipFile(zipFilePath);
//创建枚举变量
Enumeration e = zf.entries();
//遍历枚举变量
while (e.hasMoreElements()){
//获得zipentry对象
ZipEntry entry = (ZipEntry)e.nextElement();
if(!entry.getName().endsWith(".txt")){
continue;
}
//利用用户选择的文件夹和zipEntrty对象名称创建解压后的文件
File currentFile = new File(targerFolder + File.separator + entry.getName());
FileOutputStream out = null;
InputStream in = null;
try {
in = zf.getInputStream(entry);
out = new FileOutputStream(currentFile);
int buffer = 0;
while ((buffer = in.read()) != -1){
out.write(buffer);
}
}catch (Exception e1){
e1.printStackTrace();
}finally {
in.close();
out.close();
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
try {
zf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}