• Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedWriter problems

 
Calvin Williamson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Haven't used java for long, and am still learning the basics, but currently trying to get something back in a file.

I have been able to read a file, put that data into a table, add to the contents in the table, and I now need to be able to write that information back to the file.

Not sure where to do with it what so ever, the data is held in an array, So I tried to use a for loop to make sure that each entry is written back to the file, but can't get it to work. It complains about the use of '.length' which I understood got the length of the array!?

Any help would be great!
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us your code and the text of the error your are getting?
http://faq.javaranch.com/java/TellTheDetails
 
Calvin Williamson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I think that I've now got the for loop to work...but haven't got anything writing back to the file yet. The "System.out.println" statement does output the right data though...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure to close the BufferedWriter

bw.close();

when you're through with it; the data may not actually appear in the file until you do.
 
Calvin Williamson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That has seemed to help a fair amount, thank you. However, only the first entry is written back to the file. it will write them all using the System.out.println statement, but not back to the file

Also I'm getting an IO exception after the second one on the system.out.println of

"java.io.IOException: Stream closed"
[ January 02, 2009: Message edited by: Calvin Williamson ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Calvin Williamson:

Also I'm getting an IO exception after the second one on the system.out.println of

"java.io.IOException: Stream closed"


You need to close the file outside the loop -- i.e., after you're all done writing to the file. It sounds like you're closing the file inside the loop, after writing the first line.
 
Calvin Williamson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh, that's sorted that, Thank you so much
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!