StringWriter close() method in Java with Examples Last Updated : 29 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The close() method oStringWriter Class in Java is used to close the writer. Closing a writer deallocates any value in it or any resources associated with it. The StringWriter instance once closed won't work. Also a StringWriter instance once closed cannot be closed again. Syntax: public void close() Parameters: This method does not accepts any parameter. Return Value: This method does not returns any value. It just closes the Stream. Below programs illustrates the working of close() method: Program 1: Java // Java program to demonstrate // StringWriter close() method import java.io.*; class GFG { public static void main(String[] args) { // The string to be written in the Stream String str = "GeeksForGeeks"; try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Write the above string to this writer // This will put the string in the writer // till it is printed on the console writer.write(str); System.out.println(writer.toString()); // Now close the writer // using close() method writer.close(); } catch (Exception e) { System.out.println(e); } } } Output: GeeksForGeeks Program 2: Java // Java program to demonstrate // StringWriter close() method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Write the char to this writer // This will put the char in the writer // till it is printed on the console writer.write(65); System.out.println(writer.toString()); // Now close the writer // using close() method writer.close(); } catch (Exception e) { System.out.println(e); } } } Output: A Comment More infoAdvertise with us Next Article StringWriter close() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-IO package Java-StringWriter Practice Tags : Java Similar Reads PrintWriter close() method in Java with Examples The close() method of PrintWriter Class in Java is used to close the stream. Closing a stream deallocates any value in it or any resources associated with it. The PrintWriter instance once closed won't work. Also a PrintWriter instance once closed cannot be closed again. Syntax: public void close() 2 min read StringReader close() method in Java with Examples The close() method of StringReader 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 effect. 2 min read Scanner close() method in Java with Examples The close() method ofjava.util.Scanner class closes the scanner which has been opened. If the scanner is already closed then on calling this method, it will have no effect. Syntax: public void close() Return Value: The function does not return any value. Below programs illustrate the above function: 1 min read StringWriter flush() method in Java with Examples The flush() method of StringWriter Class in Java is used to flush the writer. By flushing the writer, it means to clear the writer of any element that may be or maybe not inside the writer. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do 2 min read PrintStream close() method in Java with Examples The close() method of PrintStream Class in Java is used to close the stream. Closing a stream deallocates any value in it or any resources associated with it. The PrintStream instance once closed won't work. Also a PrintStream instance once closed cannot be closed again. Syntax: public void close() 2 min read Like