Java IO Tutorial - Java CharArrayWriter .writeTo (Writer out)








Syntax

CharArrayWriter.writeTo(Writer out) has the following syntax.

public void writeTo(Writer out)  throws IOException

Example

In the following code shows how to use CharArrayWriter.writeTo(Writer out) method.

//  w  w w .j  a v a 2s .  c  o m
import java.io.CharArrayWriter;

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

    String str = "from java2s.com!";

    CharArrayWriter chw = new CharArrayWriter();

    // create destination character array writer
    CharArrayWriter chwd = new CharArrayWriter();

    chw.write(str);

    chw.writeTo(chwd);

    // print the destination buffer content as string
    System.out.println(chwd.toString());

  }
}

The code above generates the following result.