How to append a Text file?
posted 14 years ago
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.)