Java.io.FilterOutputStream.Close()方法實例
java.io.FilterOutputStream.Close() 方法關閉該流並釋放與該流關聯的所有係統資源。
聲明
以下是java.io.FilterOutputStream.Close()方法的聲明:
public void close()
參數
-
NA
返回值
此方法不返回任何值。
異常
-
IOException -- 如果發生I/ O錯誤..
例子
下麵的示例演示java.io.FilterOutputStream.Close()方法的用法。
package com.yiibai; import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; public class FilterOutputStreamDemo { public static void main(String[] args) throws Exception { OutputStream os = null; FilterOutputStream fos = null; try{ // create input streams os = new FileOutputStream("C://test.txt"); fos = new FilterOutputStream(os); // releases any system resources associated with the stream fos.close(); // writes byte to the output stream fos.write(65); }catch(IOException e){ // if any I/O error occurs System.out.print("Close() is invoked prior to write()"); }finally{ // releases any system resources associated with the stream if(os!=null) os.close(); if(fos!=null) fos.close(); } } }
讓我們編譯和運行上麵的程序,這將產生以下結果:
Close() is invoked prior to write()