Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Write a line in a new line

  Asked By: James    Date: Sep 02    Category: Java    Views: 805

I'm trying to read and write from a text file by using BufferReader
and BufferWriter. When it writing by write method, it writes without
passing line, I mean all the text file in the same line.



2 Answers Found

Answer #1    Answered By: Lurline Fischer     Answered On: Sep 02

Well thats simple, just add the string "\n" at the end of ur string. But there
are also methods just like print and println, but i dont remember the name, you
just browse the api and use them...

Answer #2    Answered By: Alfonsine Miller     Answered On: Sep 02

Yes, the BufferedWriter would write  in the same line  unless and until you insert
a separate line by the newLine() method

tempWriter.write("This is a sample line");

- use flush() method  if you want to force the writer to insert line immediately.
- You can also use "\n" in the write method to insert line, but DON'T do this.
This is not platform independent.

Didn't find what you were looking for? Find more on Write a line in a new line Or get search suggestion and latest updates.