import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.InputMismatchException; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Input the file pathname: "); String fname = in.next(); int totalMark=0; Scanner inFile=null; try { inFile = new Scanner(new File(fname)); while (inFile.hasNext()) { int x = inFile.nextInt(); if (x<0) throw new NegativeIntegerException("-ve number", x); totalMark+=x; } } catch (FileNotFoundException e) { System.out.println("Cannot open the file."); } catch (InputMismatchException e) { System.out.println("Cannot read the required number from the opened file."); } catch (NegativeIntegerException e) { System.out.println(e.getMessage()+" ["+e.getProblemValue()+"]"); } finally { if (inFile != null) { System.out.println("Closing inFile"); inFile.close(); } else { System.out.println("inFile not open"); } System.out.println("Total mark so far is: "+totalMark); in.close(); } } } /* Rundown 1 */ /* Rundown 2 */