import java.io.File; import java.io.IOException; import java.util.Scanner; public class ScannerReadingNumbersFromFile { public static void main(String[] args) throws IOException { Scanner file = new Scanner(new File("numbers.txt")); // the file numbers.txt must contain integers separated by spaces or on different // lines and the file must be located at the root level of the project folder int num = 0; int sum = 0; // this loop continues until it has read all the numbers in the file while (file.hasNext()) { num = file.nextInt(); sum += num; } System.out.println("The sum is " + sum); } }