import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(System.in); System.out.print("Input the file pathname: "); String fname = in.next(); Scanner inFile = new Scanner(new File(fname)); int x = inFile.nextInt(); System.out.println("Data is: "+x); inFile.close(); in.close(); } } /* Rundown [in case the file exists and data is read successfully] Input the file pathname: data001.txt Data is: 678 */ /* Rundown [in case the file doesn't exist, the printStackTrace method of FileNotFoundException is invoked and show the following output] Input the file pathname: data02.txt Exception in thread "main" java.io.FileNotFoundException: data02.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(Unknown Source) at java.util.Scanner.(Unknown Source) at Main.main(Main.java:13) */ /* Rundown [in case the beginning of the file is not a number, the printStackTrace method of InputMismatchException is invoked and show the following output] Input the file pathname: data002.txt Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at Main.main(Main.java:14) */