1

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

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

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

在此处输入图像描述

4

1 回答 1

2

根据JavaDoc

public int read(byte[] b)
         throws IOException

从此输入流中读取最多 byte.length 个字节的数据到一个字节数组中。此方法阻塞,直到某些输入可用

该方法只执行调用 read(b, 0, b.length) 并返回结果。

由于长度tempEntry为 0,因此不会从 Stream 中读取任何内容

于 2017-10-05T04:28:38.953 回答