try-with-resources문
2022. 12. 8. 00:06ㆍ자바
728x90
<자동으로 파일 닫기>
try(FileInputStream fin = new FileInputStream(args[0]))//괄호 안에 사용할 자원 초기화
{...
} catch(IOException e) {
System.out.println("An I/O Error Occurred");
}
try 블록이 끝난 후 자원이 자동으로 릴리즈 됨
try ( FileInputStream fin = new FileInputStream(args[0]);
FileOutputStream fout = new FileOutputStream(args[1]) )
//두 개 이상의 자원을 명시 할 때는 세미콜론으로 구분
{...
}
catch(IOException e) {
System.out.println("I/O Error: " + e);
}
728x90