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;
}
}

+ Recent posts