读取 6 MB(未压缩 25 MB)的 zip 文件时,我遇到了 OutOfMemoryError。我只有在通过遍历条目获取流时出现错误,如果我使用ZipFile.getInputStream(ZipEntry)
.
例如,这是有效的:
ZipFile zip = new ZipFile(file);
ZipEntry entry = zip.getEntry("file.xml");
InputStream is = zip.getInputStream(entry);
// Do stuff with is (loading the xml file in memory)
这不是:
ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
ZipEntry entry = zis.getNextEntry();
while(entry != null) {
if(entry.getName().equals("file.xml")) {
// Do stuff with zis (loading the xml file in memory)
}
entry = zis.getNextEntry();
}
zis.close();
有谁知道为什么?
谢谢