简体   繁体   中英

Java heap space error while parsing large xml file

I want to parse a large xml file(785mb) and write the data to csv. I am getting java heapspace error(out of memory) when I try to parse the file. I tried increasing the heap size to 1024mb but the code could handle a file of 50mb maximum.

Please let me know a solution for parsing large xml file in java.

You should use a SAXParser instead of a DOMParser The difference is that it doesn't load the complete XML data in memory.

Look at this tutorial : http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/

Regards,

Romain.

The solution here is to use Streaming Api for XML (StAX). Here is good tutorial .

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