Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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/bcd.zip

How to read a zip file inside zip file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
87 views
Welcome To Ask or Share your Answers For Others

1 Answer

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));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...