CharArrayWriter writeTo() method in Java with Examples
Last Updated :
05 Jun, 2020
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
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
CharArrayWriter charArrayWriter
= new CharArrayWriter();
String str = "GEEKS" ;
charArrayWriter.write(str);
CharArrayWriter out
= new CharArrayWriter();
charArrayWriter.writeTo(out);
System.out.println(
out.toString());
}
}
|
Program 2:
Java
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
CharArrayWriter charArrayWriter
= new CharArrayWriter();
charArrayWriter.write( "GEEKSFORGEEKS" );
CharArrayWriter out
= new CharArrayWriter();
charArrayWriter.writeTo(out);
System.out.println(
out.toString());
}
}
|
References:
https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#writeTo(java.io.Writer)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...