Skip to content

Instantly share code, notes, and snippets.

@poad
Created March 13, 2013 13:20
Show Gist options
  • Save poad/5151969 to your computer and use it in GitHub Desktop.
Save poad/5151969 to your computer and use it in GitHub Desktop.
Java6でのリソースと例外処理 ref: http://qiita.com/items/4cb9b0791e2f882cefff
InputStream in = null;
try {
in = new FileInputStream("test.txt");
// stream操作
} catch (IOException e) {
// error処理
} finally {
try { // 必要に応じて
if (in != null) {
in.close();
}
} catch (IOException e) {
}
}
try {
InputStream in = new FileInputStream("test.txt");
try {
// stream操作
} finally {
try { // 必要に応じて
in.close();
} catch (IOException e) {
}
}
} catch (IOException e) {
// error処理
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment