item9) try-with-resources를 사용하자
try-finally 구조
try-with-resources 구조
static String firstLineOfFile(String path, String defaultVal) {
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
return br.readLine();
}
catch (IOException e) {
return defaultVal;
}
}Last updated