아이템9 try-finally보다는 try-with-resources를 사용하라
Effective Java 3e 아이템 9를 요약한 내용 입니다.
static void copy(String src, String dst) throws IOException {
InputStream in = new FilInputStream(src);
try {
OutStream out = new FileOutputStream(dst);
try {
byte[] buf = new byte[BUFFER_SIZE];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
} finally {
out.close();
}
} finally {
in.close();
}
}정리
Last updated