자원이 둘 이상이면 try-finally 방식은 너무 지저분하다.
//기본 try-finally문
static void copy(String src, String dst) throws IOException{
InputStream in = new FileInputStream(src);
try{
OutputStream out = new FileOutputStream(dst);
try{
...
} finally{
out.close();
}
}
//try-with-resources 적용
static void copy(String src, String dst) throws IOException{
try(InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst)){
...
}