El método writeTo(Writer) de la clase CharArrayWriter en Java se utiliza para escribir el contenido de CharArrayWriter en otro flujo de caracteres.
Sintaxis:
public void writeTo(Writer out) throws IOException
Parámetros: este método acepta un parámetro que representa el flujo de salida que es el flujo de destino.
Valor devuelto : este método no devuelve ningún valor.
Excepciones: este método lanza IOException si ocurre un error de E/S.
Los siguientes programas ilustran el método writeTo(Writer) en la clase CharArrayWriter en el paquete IO:
Programa 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()); } }
Producción:
GEEKS
Programa 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()); } }
Producción:
GEEKSFORGEEKS
Referencias:
https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#writeTo(java.io.Writer)