ZipInputStream和OutOfMemoryError

时间:2013-11-16 19:00:54

标签: java out-of-memory zipfile zipinputstream

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

有谁知道为什么?

由于

0 个答案:

没有答案