ほとんどの場合、finally ブロックが使用されているのは、次のようなものだけです。
FileInputStream f;
try{
f= new FileInputStream("sample.txt");
//something that uses f and sometimes throws an exception
}
catch(IOException ex){
/* Handle it somehow */
}
finally{
f.close();
}
私の質問は、f のスコープが囲んでいるブロックで終わっている場合、なぜそれを finally で閉じる必要があるのでしょうか?