[英]Java heap space error while parsing large xml file
I want to parse a large xml file(785mb) and write the data to csv. 我想解析一个较大的xml文件(785mb),并将数据写入csv。 I am getting java heapspace error(out of memory) when I try to parse the file.
尝试解析文件时,我收到Java堆空间错误(内存不足)。 I tried increasing the heap size to 1024mb but the code could handle a file of 50mb maximum.
我尝试将堆大小增加到1024mb,但是代码可以处理最大50mb的文件。
Please let me know a solution for parsing large xml file in java. 请让我知道在Java中解析大型xml文件的解决方案。
You should use a SAXParser instead of a DOMParser The difference is that it doesn't load the complete XML data in memory. 您应该使用SAXParser而不是DOMParser。区别在于它不会在内存中加载完整的XML数据。
Look at this tutorial : http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/ 查看本教程: http : //www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/
Regards, 问候,
Romain. 罗曼
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.