2017-10-05 19 views
1

我想解压档案, zis.getNextEntry()给我nextEntry,我可以看到正确的条目名称,但zip输入流本身是空的。为什么?尽管条目存在,为什么zipInputStream是空的?

byte[] htmlFile = new byte[]{};   
     ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(template.getKey().getFileBase64())); 
     zis = new ZipInputStream(bais); 
     ZipEntry ze = null; 
     try { 
      while ((ze = zis.getNextEntry()) != null) { 
       if (!ze.isDirectory()) { 
        byte[] tempEntry = new byte[]{}; 
        try { 
         zis.read(tempEntry); 
        } catch (IOException e1) { 
         e1.printStackTrace(); 
        }       
       } 
      } 
      try { 
       zis.closeEntry(); 
       zis.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

下面是一些调试信息,在这里你可以看到 - 在条目存在,但没有从流中读取:

enter image description here

回答

2

JavaDoc

public int read(byte[] b) 
     throws IOException 

将此输入流中的byte.length字节数据读入 数组的字节。此方法阻塞,直到某些输入可用

此方法只执行读取呼叫(b,0,b.length)并返回 结果。

由于tempEntry长度为0,因此没有东西从流读取

相关问题