我在读取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();

有谁知道为什么?

谢谢