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 ww. jav a 2 s. c om*/
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.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »