Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Writing a StringBuffer to file (without using toString)

807607Jan 8 2007 — edited Jan 12 2007
Hi there,

I have some data in a StringBuffer which needs written out to a file. Previously I've simply used the toString() method of StringBuffer, i.e.
myWriter.write(myBuffer.toString());
However I encounter problems when the StringBuffer gets really big (around 10 million characters) - an out of memory error is generated when calling the toString() method. Is there a way to write this StringBuffer to a file without first having to create a string? Or perhaps an alternative way instead of using a StringBuffer?

(If not, I could bypass appending to the StringBuffer by writing directly to the writer, however it is better for me to be able to call one function which returns the full data instead of passing writers around)

Cheers
Dan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 9 2007
Added on Jan 8 2007
20 comments
5,136 views