Java-io-filterinputstream-close
提供:Dev Guides
public void close()メソッド
説明
- java.io.FilterInputStream.close()*メソッドは、この入力ストリームを閉じ、ストリームに関連付けられたシステムリソースを解放します。
宣言
以下は* public void close()*メソッドの宣言です-
public void close()
パラメーター
NA
戻り値
メソッドは値を返しません。
例外
*IOException* -I/Oエラーが発生した場合。
例
次の例は、public void close()メソッドの使用方法を示しています。
package com.finddevguides;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
public class FilterInputStreamDemo {
public static void main(String[] args) throws Exception {
InputStream is = null;
FilterInputStream fis = null;
try {
//create input streams
is = new FileInputStream("C://test.txt");
fis = new BufferedInputStream(is);
//closes and releases the associated system resources
fis.close();
//read is called after close() invocation
fis.read();
} catch(IOException e) {
System.out.print("stream is closed prior ot this call");
} finally {
//releases any system resources associated with the stream
if(is!=null)
is.close();
if(fis!=null)
fis.close();
}
}
}
テキストファイル* c:/test.txt*があり、次の内容があるとします。 このファイルは、サンプルプログラムの入力として使用されます-
ABCDEF
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
stream is closed prior ot this call