import java.io.*; class readText { public static void main(String[] args) { int sum = 0; int currentLine; // stores the integer of the current line try{ FileReader in = new FileReader(args[0]); BufferedReader data = new BufferedReader(in); // read the first line of input file String s = data.readLine(); while (s!=null) { // get the int value of the current line currentLine = (new Integer(s)).intValue(); System.out.println("current line: " + currentLine); // add the current integer to sum sum += currentLine; // read the next line s = data.readLine(); } in.close(); data.close(); } catch (NumberFormatException e){ // input file must have exactly one integer each line System.out.println("Data format error in input file"); } catch (IOException e){ System.out.println("Unable to read input file"); } System.out.println("sum = " + sum); } }