0

Does anyone know how to make a nextline? Usually I use the "\n" characters but when I open the .txt I wrote, I see it didn't went to the nextline. Here's the code:

FileWriter f=new FileWriter(path);
f.write("bla bla \n");
f.write("bla bla");
apxcode
  • 7,614
  • 7
  • 27
  • 40
SiK
  • 99
  • 1
  • 6

2 Answers2

0

Wrap a BufferedWriter around it, which you should be doing anyway, and use BufferedWriter.newLine().

Or use a PrintWriter, but beware that it swallows exceptions.

If that doesn't solve your problem, use \r\n instead of just \n.

user207421
  • 298,294
  • 41
  • 291
  • 462
  • Thank you very much!! It works with \r\n – SiK May 10 '14 at 20:07
  • You can use `System.getProperty("line.separator")` to get the system's newline character, so your code would work on all platforms. – awksp May 10 '14 at 20:29
0

Try the following:

BufferedWriter f = new BufferedWriter(new FileWriter(path));
f.write("bla bla ");
f.newLine();
f.write("bla bla");
jakubr
  • 305
  • 1
  • 8