Item 9. try-with-resources
try-finally ์ฌ์ฉ
class Test {
// ํ๋์ ์์์ ํ์ํ๋ ๊ฒฝ์ฐ
static String firstLineOfFile(String path) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close(); // ์ฌ๊ธฐ์ ๋ฐ์ํ ์์ธ๋ง stack trace์ ๋จ์
}
}
}try-with-resources ์ฌ์ฉ
AutoCloseable ์ธํฐํ์ด์ค
AutoCloseable ์ธํฐํ์ด์ค
try-with-resources ๊ตฌ๋ฌธ
try-with-resources ๊ตฌ๋ฌธLast updated