import java.io.File;
import java.util.Scanner;
import javax.swing.JOptionPane;
/*
 * TwoScannersTextFileExample2.java
 *
 * Created on February 27, 2005, 2:11 PM
 */

/**
 *
 * @author Bill Kraynek
 */
public class TwoScannersTextFileExample2 {
    
    /** Creates a new instance of TwoScannersTextFileExample2 */
    public TwoScannersTextFileExample2() throws Exception {
        // the file being read must be in the parent folder of the src folder
        Scanner fileScanner = new Scanner(new File("numbers2.txt"));
        int sum = 0;
        while( fileScanner.hasNext() ) {
            String nextLine = fileScanner.nextLine();
            Scanner lineScanner = new Scanner(nextLine);
            // there can be any number of ints on a line
            while( lineScanner.hasNext() ){
                sum += lineScanner.nextInt();
            }// end while
        } // end while
        JOptionPane.showMessageDialog(null,"The sum of all the numbers is " + sum + ".");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        new TwoScannersTextFileExample2();
    }
    
}

