Java.io.PrintWriter.close() 方法


Java.io.PrintWriter.close() 方法

package com.codingdict;



import java.io.*;



public class PrintWriterDemo {



   public static void main(String[] args) {

      String s = "Hello World ";



      try {



         // create a new stream at system

         PrintWriter pw = new PrintWriter(System.out);



         // append the sequence

         pw.append(s);



         // flush the writer

         pw.flush();



         // print another string

         pw.println("This is an example");



         // flush the writer again

         pw.flush();



         // close the writer

         pw.close();



      } catch (Exception ex) {

         ex.printStackTrace();

      }

   }

}