Read a zip file inside zip file

后端 未结 4 1409
长情又很酷
长情又很酷 2020-12-11 16:14

I have zip file which is inside a folder in zip file please suggest me how to read it using zip input stream.

E.G.:

abc.zip
    |
      documents/b         


        
4条回答
  •  一生所求
    2020-12-11 17:00

    If you want to look through zip files within zip files recursively,

        public void lookupSomethingInZip(InputStream fileInputStream) throws IOException {
            ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
            String entryName = "";
            ZipEntry entry = zipInputStream.getNextEntry();
            while (entry!=null) {
                entryName = entry.getName();
                if (entryName.endsWith("zip")) {
                    //recur if the entry is a zip file
                    lookupSomethingInZip(zipInputStream);
                }
                //do other operation with the entries..
    
                entry=zipInputStream.getNextEntry();
            }
        }
    

    Call the method with the file input stream derived from the file -

    File file = new File(name);
    lookupSomethingInZip(new FileInputStream(file));
    

提交回复
热议问题