为什么 zipInputStream 是空的,但条目存在?
Why zipInputStream is empty though entry exists?
我正在尝试解压缩存档,
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();
}
下面是一些调试信息,您可以在其中看到 - 条目存在,但未从流中读取任何内容:
根据JavaDoc
public int read(byte[] b)
throws IOException
Reads up to byte.length bytes of data from this input stream into an
array of bytes. This method blocks until some input is available
This method simply performs the call read(b, 0, b.length) and returns
the result.
由于 tempEntry
的长度为 0,因此不会从流中读取任何内容
我正在尝试解压缩存档,
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();
}
下面是一些调试信息,您可以在其中看到 - 条目存在,但未从流中读取任何内容:
根据JavaDoc
public int read(byte[] b)
throws IOException
Reads up to byte.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available
This method simply performs the call read(b, 0, b.length) and returns the result.
由于 tempEntry
的长度为 0,因此不会从流中读取任何内容