Java IO Tutorial - Java BufferedWriter.write(String s, int off, int len)








Syntax

BufferedWriter.write(String s, int off, int len) has the following syntax.

public void write(String s,  int off,  int len)  throws IOException

Example

In the following code shows how to use BufferedWriter.write(String s, int off, int len) method.

//from w  w w .ja  v  a  2 s.co m

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

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

    String str = "from java2s.com!";

    // create string writer
    StringWriter sw = new StringWriter();

    // create buffered writer
    BufferedWriter bw = new BufferedWriter(sw);

    // writing string to writer
    bw.write(str,1,4);

    // forces out the characters to string writer
    bw.flush();

    // string buffer is created
    StringBuffer sb = sw.getBuffer();

    System.out.println(sb);

  }
}

The code above generates the following result.