• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to append a Text file?

 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have a Text file ,I have some content in that file.I want to append at the end of the file in a new line.I used PrintWriter to write the string with escape character ("\n") but this failed.Is there any easier way to do this?
Happy middling with java.
Netharam.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Windows, you probably should have a "\r\n" rather than "\n". Also, make sure you close the file afterwards - or at least flush it. You can take care of both these problems at once with a PrintWriter constructed with autoFlush set to true (see PrintWriter constructors in API). Using the println() method appends a platform-specific line separator and flushes the stream, ensuring that what you think you've written isn't still hiding in a buffer somewhere. (Of course, this diminishes the effectiveness of using things like BufferedWriter, so it's a trade-off.)
 
Vikrama Sanjeeva
Ranch Hand
Posts: 760
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I use this code,


Bye,
Viki.}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!