和相InputStream與FileInputStream一樣,Java提供OutputStream與FileOutputStream,用來處理文件寫入操作。同樣的OutputStream是FileOutputStream的上層(父層)。可用FileOutputStream來建立一個OutputStream的方法,然後用OutputStream的方法(methods)進行操作。
OutputStream f = new FileOutputStream("C:/java/hello")
以下是OutputStream的方法(methods):
1 public void close() throws IOException{}
This method closes the file output stream. Releases any system resources associated with the file. Throws an IOException.
2 protected void finalize()throws IOException {}
This method cleans up the connection to the file. Ensures that the close method of this file output stream is called when there are no more references to this stream. Throws an IOException.
3 public void write(int w)throws IOException{}
This methods writes the specified byte to the output stream.
4 public void write(byte[] w)
Writes w.length bytes from the mentioned byte array to the OutputStream.