PrintWriter flush() method in Java with Examples Last Updated : 29 Jan, 2019 Comments Improve Suggest changes Like Article Like Report The flush() method of PrintWriter Class in Java is used to flush the stream. By flushing the stream, it means to clear the stream of any element that may be or maybe not inside the stream. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do not accepts any parameter. Return Value: This method do not returns any value. It just flushes the Stream. Below methods illustrates the working of flush() method: Program 1: Java // Java program to demonstrate // PrintWriter flush() method import java.io.*; class GFG { public static void main(String[] args) { // The string to be written in the Writer String str = "GeeksForGeeks"; try { // Create a PrintWriter instance PrintWriter writer = new PrintWriter(System.out); // Write the above string to this writer // This will put the string in the stream // till it is printed on the console writer.write(str); // Now clear the stream // using flush() method writer.flush(); } catch (Exception e) { System.out.println(e); } } } Output: GeeksForGeeks Program 2: Java // Java program to demonstrate // PrintWriter flush() method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a PrintWriter instance PrintWriter writer = new PrintWriter(System.out); // Write the char to this writer // This will put the char in the stream // till it is printed on the console writer.write(65); // Now clear the stream // using flush() method writer.flush(); } catch (Exception e) { System.out.println(e); } } } Output: A Comment More infoAdvertise with us Next Article PrintWriter flush() method in Java with Examples K Kirti_Mangal Follow Improve Article Tags : Java Java-Functions Java-IO package Java-PrintWriter Practice Tags : Java Similar Reads 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 flush() method in Java with Examples The flush() method of PrintStream Class in Java is used to flush the stream. By flushing the stream, it means to clear the stream of any element that may be or maybe not inside the stream. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do 2 min read PrintWriter print(float) method in Java with Examples The print(float) method of PrintWriter Class in Java is used to print the specified float value on the stream. This float value is taken as a parameter. Syntax: public void print(float floatValue) Parameters: This method accepts a mandatory parameter floatValue which is the float value to be written 2 min read Writer flush() method in Java with Examples The flush() method of Writer 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 not a 2 min read 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 Like