Java.io.OutputStream.close() 方法


Java.io.OutputStream.close() 方法

package com.codingdict;



import java.io.*;



public class OutputStreamDemo {



   public static void main(String[] args) {

      try {



         // create a new output stream

         OutputStream os = new FileOutputStream("test.txt");



         // craete a new input stream

         InputStream is = new FileInputStream("test.txt");



         // write something

         os.write('A');



         // flush the stream

         os.flush();



         // close the stream but it does nothing

         os.close();



         // read what we wrote

         System.out.println("" + (char) is.read());



      } catch (Exception ex) {

         ex.printStackTrace();

      }



   }

}