// purpose: demonstrate file-based input processing import java.util.*; import java.io.*; public class SixNumbersFromFile { // method main(): program starting point public static void main( String[] args ) throws IOException { // set up input scanner Scanner stdin = new Scanner( System.in ); // get name of file to be processed System.out.print( "What is your file: " ); String s = stdin.next(); // get a representation of the file File f = new File( s ); // get connection to the file Scanner reader = new Scanner( f ); // get data from the file int n1 = reader.nextInt(); int n2 = reader.nextInt(); int n3 = reader.nextInt(); int n4 = reader.nextInt(); int n5 = reader.nextInt(); int n6 = reader.nextInt(); // sum and display int sum = n1 + n2 + n3 + n4 + n5 + n6; System.out.println( "Sum of six values from " + s + ": " + sum ); } }