스프링프레임워크공부중/1부 템플릿 패턴 따라잡기
2단계 자원반납 팩토링
행복한 수지아빠
2010. 12. 18. 18:27
반응형
package springbook.learningtest.template;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Calculator {
public Integer calcSum(String filepath) {
BufferedReader br = null;
int sum = 0;
try {
br = new BufferedReader(new FileReader(filepath));
String line = null;
while( (line=br.readLine())!=null ){
sum += Integer.parseInt(line);
}
br.close();
} catch (IOException ie) {
// TODO: handle exception
ie.printStackTrace();
} catch (Exception e){
e.printStackTrace();
} finally {
if(br!=null){
try {
br.close();
} catch (Exception e2) {
// TODO: 무시
}
}
}
return sum;
}
}
반응형