I am trying to load a file called SPY.txt
into an array, but I can't even get this little snippet to work.
I don't understand. If f.exists
is true
, how can the Scanner throw a file not found exception?
import java.io.*;
import java.util.Scanner;
public class ScannerTest {
public static void main(String[] args) {
File f = new File (new File("SPY.txt").getAbsolutePath());
System.out.println(f.exists());
Scanner s = new Scanner(f);
}
}
Output: True
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown at scannertest.ScannerTest.main(ScannerTest.java:13)
Line 13 is
Scanner s = new Scanner(f);