Forums Register Login

FileWriter, makes new file but no text shows

+Pie Number of slices to send: Send
I am trying to create a text file and write to it, but I can't seem to get the text to post even though the file does get created.

I have tried: FileWriter out = new FileWriter("fileOut", true );

as well as:
BufferedWriter out = new BufferedWriter(new FileWriter("fileOut", true));

and then: out.write("string stuff" + numStuff);

Any suggestions?
-JS
[ February 24, 2006: Message edited by: Jim Standish ]
+Pie Number of slices to send: Send
Hi Jim,

Welcome to JavaRanch!

The short answer: call close() on the BufferedWriter before exiting your program.

Longer answer: the BufferedWriter will hold the data in an internal buffer (hence the name!) until it gets a certain amount; then the buffer is full, and it's flushed all at once out to the file. You're writing a tiny bit, which is still in the buffer when the program exits. The file itself is closed automatically, but not the BufferedWriter, and so its buffered data is simply lost.
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 895 times.
Similar Threads
File I/O
Need help writing a text file
BufferedWriter to byte []
Need help writing to a text file
write a int to a file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:38:28.