Recent Posts
Recent Comments
반응형
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

오늘도 공부

2단계 자원반납 팩토링 본문

스프링프레임워크공부중/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;
}
}

반응형