1. 程式人生 > >不解壓壓縮包直接解析內部檔案(zip)

不解壓壓縮包直接解析內部檔案(zip)

ZipInputStream.getNextEntry()____________獲取壓縮檔案內下一個檔案,如果當前位置是資料夾則從資料夾內獲取
ZipFile.getInputStream(ZipEntry) __________獲取壓縮包內部檔案的輸入流

示例:

Workbook wb = null;
ZipFile zf = new ZipFile(url);
InputStream in = new BufferedInputStream(new FileInputStream(url));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
    String name = ze.getName();
    if (ze.isDirectory()) {
    }else if(name.substring(name.lastIndexOf(".")+1).equals("xlsx")) {
        wb = new XSSFWorkbook(zf.getInputStream(ze));
    }
}