讀取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();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM