Java BufferedWriter.newLine()

Syntax

BufferedWriter.newLine() has the following syntax.

public void newLine()  throws IOException

Example

In the following code shows how to use BufferedWriter.newLine() method.


/*from ww  w . j av  a  2s  . com*/

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;

public class Main {
  public static void main(String[] args) throws IOException {

    String s = "from java2s.com!";

    StringWriter sw = new StringWriter();

    BufferedWriter bw = new BufferedWriter(sw);

    bw.write(s, 0, 5);

    bw.newLine();

    bw.write(s, 6, s.length() - 6);

    bw.flush();

    System.out.print(sw.getBuffer());

  }
}

The code above generates the following result.