CharArrayWriter writeTo() method in Java with Examples Last Updated : 05 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The writeTo(Writer) method of CharArrayWriter class in Java is used to write the contents of the CharArrayWriter to another character stream.Syntax: public void writeTo(Writer out) throws IOException Parameters: This method accepts one parameter out that represents the output stream that is the destination stream.Return value: This method does not return any value.Exceptions: This method throws IOException if an I/O error occurs.Below programs illustrate writeTo(Writer) method in CharArrayWriter class in IO package:Program 1: Java // Java program to illustrate // CharArrayWriter writeTo(Writer) method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Create charArrayWriter CharArrayWriter charArrayWriter = new CharArrayWriter(); String str = "GEEKS"; charArrayWriter.write(str); // Create outputStream CharArrayWriter out = new CharArrayWriter(); charArrayWriter.writeTo(out); // print the outputStream System.out.println( out.toString()); } } Output: GEEKS Program 2: Java // Java program to illustrate // CharArrayWriter writeTo(Writer) method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Create charArrayWriter CharArrayWriter charArrayWriter = new CharArrayWriter(); charArrayWriter.write("GEEKSFORGEEKS"); // Create outputStream CharArrayWriter out = new CharArrayWriter(); charArrayWriter.writeTo(out); // print the outputStream System.out.println( out.toString()); } } Output: GEEKSFORGEEKS References: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#writeTo(java.io.Writer) Comment More infoAdvertise with us Next Article CharArrayWriter writeTo() method in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-IO package Practice Tags : Java Similar Reads CharArrayWriter write() method in Java with Examples The write() method of CharArrayWriter class in Java is of three types: The write(int) method of CharArrayWriter class in Java is used to write a character to the writer in form of an integer. This write() method writes one character at a time to the CharArrayWriter.Syntax: public void write(int c) O 3 min read CharArrayWriter size() method in Java with examples The size() method of the CharArrayWriter class in Java is used to get the current size of the buffer. Syntax: public int size() Parameters: This method does not accept any parameter.Return Value: This method returns an integer value which signifies the current size of the buffer. Below program illus 2 min read CharArrayWriter toString() method in Java with examples The toString() method of the CharArrayWriter class in Java converts the given input data to a string. Syntax: public String[] toString() Parameters: This method does not accept any parameter. Return Value: This method returns a copy of the input data. Below program illustrate the above method: Progr 1 min read CharArrayWriter append() method in Java with Examples The append() method of CharArrayWriter class in Java is of three types: The append(char) method of CharArrayWriter class in Java is used to append the specified character to the writer. This append() method appends one character at a time to the CharArrayWriter and returns this CharArrayWriter.Synta 3 min read CharArrayWriter toCharArray() method in Java with examples The toCharArray() method of the CharArrayWriter class in Java returns a copy of the input data.Syntax: public char[] toCharArray() Parameters: This method does not accept any parameter.Return Value: This method returns a copy of the input data. Below program illustrate the above method: Program 1: J 2 min read Like