• Post Reply Bookmark Topic Watch Topic
  • New Topic

unable to write to a text file !  RSS feed

 
Arjun Singh Rampal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see my code. The program runs, but my output file is 0 kb, ie blank How do i make it work ? I also get some warnings, how do i remove them ?

 
Micheal Quai
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"//out.close(); " ------------"out.close();"
you must use close() to close the file . if you don't do that ,the data will not save in the file .

[my english is so poor.]
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very important to close a writer or a reader. Search for examples of closing it in a finally block. If you don’t make sure to close it definitely, you might end up with the file handle occupied for ever.

Another problem is that you might never flush the writer. If you don’t flush the writer, the text remains in the writer, gradually building up until it is enough to be worth writing. If you look at the documentation for close, you find out that close usually flushes the stream, too.
It is bad practice to comment out close() lines (except for System.in and similar); comment it back in and see how much better the whole thing works
 
Micheal Quai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:It is very important to close a writer or a reader. Search for examples of closing it in a finally block. If you don’t make sure to close it definitely, you might end up with the file handle occupied for ever.

Another problem is that you might never flush the writer. If you don’t flush the writer, the text remains in the writer, gradually building up until it is enough to be worth writing. If you look at the documentation for close, you find out that close usually flushes the stream, too.
It is bad practice to comment out close() lines (except for System.in and similar); comment it back in and see how much better the whole thing works


thank you .i feel very helpful very much .
 
Arjun Singh Rampal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome both of you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!