简体   繁体   中英

Java - Getting an OutOfMemoryError while parsing a ZipInputStream

I have a problem reading the content of a zip file retrieved from a webservice.

The zip file is stored in a byte array called bytes as you can see in the code below.

ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bytes.get()));
String rawJson = IOUtils.toString(zis);

When I execute IOUtils.toString(zis) I get an OutOfMemoryError: Java heap space .

I'm shure that the problem is caused by the dimension of the json file contained in the zip, is bigger than 150MB. I've tried with other smaller files and I can get the json content without any problem.

Is there a way to read the content of the zip without storing it in memory?

EDIT: I know that I could increase my heap memory but I'm looking for a code-based solution because it woud work on any environment.

If u are using IDE, then try to do this

Run Configuration > Arguments > -Xmx7048m

increase the maximum ram to compile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM