Java IO Tutorial - Java StringWriter.flush()








Syntax

StringWriter.flush() has the following syntax.

public void flush()

Example

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

import java.io.*;
/*w  w  w .  j  a  v  a 2s .  c om*/
public class Main {

   public static void main(String[] args) {

      
      StringWriter sw = new StringWriter();

      // create a new sequence
      String s = "from java2s.com";

      // write a string
      sw.write(s);

      // flush the writer
      sw.flush();

      System.out.println(sw.toString());


   }
}

The code above generates the following result.