How can I read files from Zip file to memory with Java?

后端 未结 1 1440
醉话见心
醉话见心 2021-02-04 15:50

I found example from SUN site (http://java.sun.com/developer/technicalArticles/Programming/compression/), but it returns BufferedOutputStream. But I would like to get ZipEntry f

相关标签:
1条回答
  • 2021-02-04 16:28

    Well, just change the part that writes the file into something you want to do with the data.

    while((entry = zis.getNextEntry()) != null) {
        System.out.println("Extracting: " + entry);
        int count;
        byte[] data = new byte[BUFFER];
        String filename = entry.getName();
        System.out.println("Filename: " + filename);
        while ((count = zis.read(data, 0, BUFFER)) != -1) {
           // Do whatever you want with the data variable
           System.out.println(data);
        }
    }
    
    0 讨论(0)
提交回复
热议问题