Why ZipInputStream can't read the output of ZipOutputStream?

后端 未结 5 1960
夕颜
夕颜 2021-01-18 08:20

I\'m stuck with this junit test:

public void test() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ZipOutputStream zipOu         


        
5条回答
  •  孤独总比滥情好
    2021-01-18 08:50

    Read API doc for ZipEntry. It says "if known". You can read the content using the following (it just prints the size of the zipentry, change it process data appropriately):

    ZipEntry entry = zipIn.getNextEntry();
    int BUFSIZE = 1024;
    byte [] buffer = new byte[BUFSIZE];
    int read = 0;
    int total = 0;
    while( (read = zipIn.read(buffer, 0, BUFSIZE)) >0 ) { 
      total += read;
      // what do you want to do with the data read? Do it here
    }   
    System.err.println("Total: " + total);
    

提交回复
热议问题