Writer flush() method in Java with Examples Last Updated : 29 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 accepts any parameter. Return Value: This method do not returns any value. It just flushes the writer. Below methods illustrates the working of flush() method: Program 1: Java // Java program to demonstrate // Writer 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 Writer instance Writer writer = new PrintWriter(System.out); // 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); // Now clear the writer // using flush() method writer.flush(); } catch (Exception e) { System.out.println(e); } } } Output: GeeksForGeeks Program 2: Java // Java program to demonstrate // Writer flush() method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a Writer instance Writer writer = new PrintWriter(System.out); // Write the char to this writer // This will put the char in the writer // till it is printed on the console writer.write(65); // Now clear the writer // using flush() method writer.flush(); } catch (Exception e) { System.out.println(e); } } } Output: A Comment More infoAdvertise with us Next Article Writer equals() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-IO package Java-Writer Practice Tags : Java Similar Reads Writer getClass() method in Java with Examples The getClass() method of Writer Class in Java is used to get the parent Class of this Writer instance. This method does not accept any parameter and returns the required Class details. Syntax of getClass() methodpublic final Class String getClass()Calling of the getClass() methodobject_name.getClass 2 min read Writer hashCode() method in Java with Example The hashCode() method of Writer Class in Java is used to get the HashCode value of this Writer instance. This method does not accepts any parameter and returns the required int value. Syntax: public int hashCode() Parameters: This method accepts does not accepts any parameter. Return Value: This met 2 min read Writer close() method in Java with Examples The close() method of Writer Class in Java is used to close the writer. Closing a writer deallocates any value in it or any resources associated with it. The Writer instance once closed won't work. Also a Writer instance once closed cannot be closed again. Syntax: public void close() Parameters: Thi 2 min read Writer write(int) method in Java with Examples The write(int) method of Writer Class in Java is used to write the specified byte value on the writer. This byte value is specified using the ASCII value of the byte value passed as an integer value. This integer value is taken as a parameter. Syntax: public void write(int ascii) Parameters: This me 2 min read Writer equals() method in Java with Examples The Java.io.Writer.equals(Object obj) method of Writer class in Java is used to check whether the two instances of Writer are equal or not. It returns a boolean stating whether they are equal or not. Signature: public boolean equals(Writer second_Writer) Syntax: first_Writer.equals(second_Writer) Pa 2 min read Console writer() method in Java with Examples The writer() method of Console class in Java is used to retrieves the unique PrintWriter object which is associated with the console. Syntax: public PrintWriter writer() Parameters: This method does not accept any parameter. Return value: This method returns the PrintWriter which is associated with 1 min read Like