Java IO Tutorial - Java CharArrayWriter.write(String str, int off, int len)








Syntax

CharArrayWriter.write(String str, int off, int len) has the following syntax.

public void write(String str,  int off,  int len)

Example

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

//from  w ww .  j av a 2  s . c o m
import java.io.CharArrayWriter;

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

    String str = "from java2s.com!";

    CharArrayWriter chw = new CharArrayWriter();

    // portion to be written to writer
    chw.write(str, 4, 9);

    // print the buffer as string
    System.out.println(chw.toString());

  }
}

The code above generates the following result.