简体   繁体   English

解析大型xml文件时出现Java堆空间错误

[英]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. 罗曼

The solution here is to use Streaming Api for XML (StAX). 此处的解决方案是使用Streaming Api for XML(StAX)。 Here is good tutorial . 这是很好的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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