How to write a Huge File.

When I am writing some content to a XML file using FileWriter.But it giving java.lang.OutOfMemoryError .TheactPolicy.toXml() returns a String.Which contains huge data of 150 MB.How to write a big file Pls help.

filetoCreate = file_path_xml + getCalendarDate() + file_name;

FileWriterfw=new FileWriter(filetoCreate);

BufferedWriterbw =new BufferedWriter(fw);

bw.write(actPolicy.toXml());

bw.close();

fw.close();

[530 byte] By [avina_SMPPa] at [2007-11-27 10:56:08]
# 1

Read and write a little at a time, rather than the entire thing at once. If this is not possible then increase your allocated memory for java (as long as you have enough physical memory) using the -Xms and -Xmx options.

masijade.a at 2007-7-29 12:01:10 > top of Java-index,Java Essentials,Java Programming...
# 2

Yurgh.

Refactor for that method to accept a stream so it can write its info to a file instead of storing it all in memory. Returning such a String is just pointless.

CeciNEstPasUnProgrammeura at 2007-7-29 12:01:10 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi CeciNEstPasUnProgrammeur ,

I didnt got what u said.,.

avina_SMPPa at 2007-7-29 12:01:10 > top of Java-index,Java Essentials,Java Programming...
# 4

Yup, as the-non-programmer says

actPolicy.toFile(file_path_xml + getCalendarDate() + file_name)

http://www.exampledepot.com/egs/javax.xml.transform/WriteDom.html looks about right to me.

Cheers, Keith.

corlettka at 2007-7-29 12:01:10 > top of Java-index,Java Essentials,Java Programming...