Posts Java new line character
Post
Cancel

Java new line character

  • Java 6 and before
1
System.getProperty("line.separator");
  • [Update For] Java 7 and above
1
System.lineSeparator() 
  • BufferedWriter
1
2
3
4
5
6
7
8
9
StringWriter stringWriter = new StringWriter();
BufferedWriter bufferedWriter = new BufferedWriter(stringWriter);
final String data = "hello";
bufferedWriter.write(data, 0, data.length());
bufferedWriter.newLine();
bufferedWriter.newLine();
bufferedWriter.write(data, 0, data.length());
bufferedWriter.flush();
System.out.print(stringWriter.getBuffer());
  • if commons-lang is already being used in the project
1
SystemUtils.LINE_SEPARATOR
This post is licensed under CC BY 4.0 by the author.