读取zip压缩文件所有目录下的文件
try {
String path = "E/a.zip";
ZipFile zf = new ZipFile(path,Charset.forName("gbk"));
Enumeration<? extends ZipEntry> zs = zf.entries();
while (zs.hasMoreElements()) {
ZipEntry ze = zs.nextElement();
//跳过目录
if (!ze.isDirectory() && ze.getSize()>0 ) {
String name = ze.getName();
InputStream input = null;
//判断文件是否包含关键字
if(name.contains("LTE")) {
//将文件读入InputStream中
if(name.endsWith(".gz")) {
input = new GZIPInputStream(zf.getInputStream(ze));
}else if (name.endsWith(".zip")){
input = new ZipInputStream(zf.getInputStream(ze));
((ZipInputStream)input).getNextEntry();
}if(name.endsWith(".XML")) {
input = zf.getInputStream(ze);
}
//处理InputStream中的数据
decode(input);
} else{
//logger.info("文件有误");
//return null;
}
}
}
zf.close();
} catch (IOException e) {
e.printStackTrace();
}