// ---------------------------------------------- // we need these imports for Scanners and file IO import java.util.Scanner; import java.io.*; // ----------------------------------------------------- // we'll put our code in a main method of a sample class class SampleFileIO { public static void main(String[] argh) { // ---------------------------------------------- // since opening a file (for a scanner) may fail, // we need to "wrap" it in a try-catch block try { // -------------------------------------------------- // once the file is open, we can scan in some numbers // REMEMBER to put the file in your code directory Scanner sc = new Scanner(new File("numbers.txt")); int n = sc.nextInt(); int m = sc.nextInt(); System.out.println("Your numbers were " + n + " and " + m + "."); } // -------------------------------------------------- // the catch block says what to do if file open fails catch (Exception e) { System.out.println("Ooops, couldn't find your file."); } } }