import java.util.*; import java.io.*; class ReadIntegers2 { public static void main(String[] args) { Reader filein; try { filein = new BufferedReader( new FileReader("numbers-errors.txt") ); } catch (FileNotFoundException e) { System.err.println("Couldn't open file."); return; // exit main() & stop program } Scanner scanfile = new Scanner(filein); int total = 0; boolean done = false; while ( !done ) { try { total += scanfile.nextInt(); } catch (InputMismatchException e) { // not an integer: eat rest of line scanfile.nextLine(); } catch (NoSuchElementException e) { // end of file done = true; } } System.out.println(total); } }