Java – Write large XML files with out-of-memory error Java

Write large XML files with out-of-memory error Java… here is a solution to the problem.

Write large XML files with out-of-memory error Java

I’m developing an app for android and I need to create a fairly large XML file.

I’ve tried with the DOM document, but because it resides in memory, it throws an “out of memory” error.

Can someone suggest an alternative solution? This is an XML file created from scratch.

Solution

I’ll write the XML to a Stream or Writer step by step to iterate through the data to be converted to XML. This way, you don’t need more memory than the original data.

Related Problems and Solutions