Results 1 to 3 of 3
Thread: [SOLVED] Writing to a file
- 04-29-2009, 05:53 PM #1
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
[SOLVED] Writing to a file
I am trying to write to a file and I don't really know what I'm doing wrong here. If someone could point me in the right direction that would be great.
It is supposed to write each field of the array to the File foo, one at a time. Each needs to be on its own line (perhaps BufferedWriter.write() moves the cursor to the next line, but I doubt it, hence the "\n"). Can anyone explain why this isn't working?Java Code:BufferedWriter writer = new BufferedWriter (new FileWriter(foo)); for (int count = 0; count <= (listArray.length - 1); count++) { writer.write(listArray[count]); writer.write("\n"); }
It is really starting to annoy me because I'm pretty sure I'm doing something stupid here and I don't know what it is.Last edited by porchrat; 04-29-2009 at 06:18 PM.
- 04-29-2009, 06:46 PM #2
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
Nevermind I figured it out.
It was something stupid after all. Above that code mentioned in the previous post I was reading a file into that array using a BufferedReader wrapped around a FileReader and I had forgotten to close that Reader.
Thanks anyway everyone :) will mark as solved
- 04-29-2009, 06:51 PM #3
flush & close
Have you tried flush() and close() ?
BufferedWriter (Java Platform SE 6)
Write to file using a BufferedWriter - A Java Code Example
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
Reading/Writing to file
By Doctor Cactus in forum New To JavaReplies: 2Last Post: 10-28-2008, 02:05 PM -
Writing to DAT or TXT file
By hunterbdb in forum Advanced JavaReplies: 7Last Post: 10-12-2008, 02:50 PM -
swapping the contents of the file and writing to another file
By Ms.Ranjan in forum New To JavaReplies: 9Last Post: 07-10-2008, 04:52 PM -
Writing to a file (at the end)
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:22 AM -
writing to a file
By bugger in forum New To JavaReplies: 1Last Post: 11-11-2007, 02:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks