• Post Reply Bookmark Topic Watch Topic
  • New Topic

Buffered Writer/FileWriter not writing to file in netbeans  RSS feed

 
David Mathie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am using netbeans to create a hotel booking system, just tessting out code to get the booking information input to a file when the next button is clicked.



Nothing is getting wrote to the file though. Does that code seem right? Thanks
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Close the writer (using the close() method) once you are completely done with writing the contents. Or else the contents won't be flushed unless explicitly flushed.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, hold on. I just noticed you are using try with resources features of Java 7, so it will be auto closed and you don't have to explicitly close it. Are you sure you are checking the correct file contents?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Mathie wrote:Nothing is getting wrote to the file though. Does that code seem right? Thanks

Looks reasonable.
1. Do you get any log messages?
2. Does anything happen if you add an explicit flush() after the last write()? Like Jaikiran says, it shouldn't, but it never hurts to try.

Winston
 
David Mathie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for the replies. Ive been used to using eclipse. In eclipse the files update in the program but for some reason it doesnt do this in netbeans. After checking the files in the actual folder i see its actually working. Thanks for the help.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for posting that. I typically avoid IDEs for running programs and instead use them more as an advanced editor for reasons like these.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!