El método close() de la clase CharArrayWriter en Java se usa para cerrar el flujo actual.
Sintaxis :
public void close()
Parámetros: Este método no acepta ningún parámetro.
Valor de retorno: este método cierra el flujo actual. Sin embargo, no libera el búfer.
El siguiente programa ilustra el método anterior:
Programa 1:
Java
// Java program to illustrate // the close() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Initializing the character array char[] geek = { 'G', 'E', 'E', 'K', 'S' }; // Initializing the CharArrayWriter CharArrayWriter char_array1 = new CharArrayWriter(); for (int c = 72; c < 77; c++) { // Use of write(int char) // Writer int value to the Writer char_array1.write(c); } // Use of size() method System.out.println("\nSize of char_array1 : " + char_array1.size()); // Close the current stream char_array1.close(); } }
Producción:
Size of char_array1 : 5
Programa 2:
Java
// Java program to illustrate // the close() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Initializing the character array char[] geek = { 'G', 'O', 'P', 'A', 'L', 'L' }; // Initializing the CharArrayWriter CharArrayWriter char_array1 = new CharArrayWriter(); for (int c = 72; c < 78; c++) { // Use of write(int char) // Writer int value to the Writer char_array1.write(c); } // Use of size() method System.out.println("\nSize of char_array1 : " + char_array1.size()); // Close the current stream char_array1.close(); } }
Producción:
Size of char_array1 : 6
Referencia : https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#close()