Computer Science Canada Writing to a file and adding on |
Author: | Aziz [ Wed Jul 06, 2005 2:45 pm ] | ||
Post subject: | Writing to a file and adding on | ||
When I write to a file, it erases the whole file, right? Is there a way to simply add to the end of a file? Or do I have to do something like this:\ (Psuedo:)
|
Author: | 1of42 [ Wed Jul 06, 2005 3:09 pm ] |
Post subject: | |
Use the optional second boolean argument to the FileWriter constructor - set it to true to append to the file instead of truncating it. |
Author: | wtd [ Wed Jul 06, 2005 4:03 pm ] |
Post subject: | |
To make it even easier, the Java API reference page on FileWriter. |
Author: | Aziz [ Wed Jul 06, 2005 7:08 pm ] |
Post subject: | |
Thanks a bunch guys, helped out a bunch |
Author: | Spartan_117 [ Fri Jul 08, 2005 12:17 pm ] |
Post subject: | |
I believe the reason it does that is becuase once u write to the file u arent closing the file (or the IO stream) if u close it it should work.. But its been a while so im not a hundred percent |
Author: | 1of42 [ Sat Jul 09, 2005 1:55 am ] |
Post subject: | |
Spartan_117 wrote: I believe the reason it does that is becuase once u write to the file u arent closing the file (or the IO stream) if u close it it should work.. But its been a while so im not a hundred percent
Nope. The reason it's truncating the file is that you have to add the boolean append argument set to true for it to add to the file instead of truncate/write a new one. Although, if he doesn't close (or flush, or checkError()) the stream, he won't get any data written at all. |
Author: | Aziz [ Sat Jul 09, 2005 9:48 am ] |
Post subject: | |
Well, of course, I always (which means, usually, when I remember) call the close() method (at least I hope I did....*paranoid* let me double-check...) |