import java.io.*; import java.util.*; public class MyFileReader { public static double sumFileContents(String path) { try { File file = new File (path); Scanner sc = new Scanner(file); double sum = 0.0; while(sc.hasNextDouble()) sum += sc.nextDouble(); System.out.println("Closing File!"); sc.close(); return sum; } catch(FileNotFoundException ex) { System.out.println("The specified file was not found at "+ path); } catch(NoSuchElementException ex) { System.out.println("The specified type of element was not found!"); } return 0.0; } public static void main(String args[]) { try { double result = sumFileContents(args[0]); System.out.println("Result is: "+result); } catch(IndexOutOfBoundsException ex) { System.out.println("No file has been specified from command line!\n"); } } }