Java.io.Writer.flush() 方法


Java.io.Writer.flush() 方法

package com.codingdict;



import java.io.*;



public class WriterDemo {



   public static void main(String[] args) {

      String s = "Hello World";



      // create a new writer

      Writer writer = new PrintWriter(System.out);



      try {



         // append a string

         writer.append(s);



         // flush the writer

         writer.flush();



         // append a new string in a new line

         writer.append("\nThis is an example");



         // flush the stream again

         writer.close();



      } catch (IOException ex) {

         ex.printStackTrace();

      }

   }

}