CharArrayWriter close() method in Java with examples Last Updated : 25 Jun, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The close() method of the CharArrayWriter class in Java is used to close the current stream. Syntax: public void close() Parameters: This method does not accept any parameter.Return Value: This method closes the current stream. However, it does not release the buffer. Below program illustrate the above method: Program 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(); } } Output: Size of char_array1 : 5 Program 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(); } } Output: Size of char_array1 : 6 Reference: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#close() Comment More infoAdvertise with us Next Article CharArrayWriter size() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java-Functions Java-IO package Java-CharArrayWriter Practice Tags : Java Similar Reads CharArrayReader close() method in Java with Examples The close() method of CharArrayReader Class in Java is used to close the stream and release the resources that were busy in the stream, if any. This method has following results: If the stream is open, it closes the stream releasing the resources If the stream is already closed, it will have no effe 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 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 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 writeTo() method in Java with Examples 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 dest 1 min read BufferedWriter close() method in Java with Examples The close() method of BufferedWriter class in Java is used to flush the characters from the buffer stream and then close it. Once the stream is closed further calling the methods like write() and append() will throw the exception. Syntax: public void close() Parameters: This method does not accept a 2 min read Like