Java IO Tutorial - Java FilterWriter.flush()








Syntax

FilterWriter.flush() has the following syntax.

public void flush()  throws IOException

Example

In the following code shows how to use FilterWriter.flush() method.

/*ww w.j ava  2  s.  c  o  m*/
import java.io.FilterWriter;
import java.io.StringWriter;
import java.io.Writer;

public class Main {
  public static void main(String[] args) throws Exception {
    Writer w = new StringWriter(6);

    FilterWriter fw = new FilterWriter(w) {};

    fw.write(65);
    
    fw.flush();

    String s = w.toString();

    System.out.print(s);
  }
}

The code above generates the following result.