input file cannot be found

Posted by Eric Smith on Stack Overflow See other posts from Stack Overflow or by Eric Smith
Published on 2012-04-08T23:20:38Z Indexed on 2012/04/08 23:29 UTC
Read the original article Hit count: 305

Filed under:

I am just messing around with reading input files with java until I got stumped at the most basic of steps... finding the input file!

The input.txt file is in the same directory as my class file that is calling it yet eclipse still gives me an error that it cant be found:

"Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type FileNotFoundException"

My code:

package pa;
import java.util.Scanner; 

public class Project {
 public static void main(String[] args) {
    java.io.File file = new java.io.File("input.txt");
    System.out.println(file.getAbsolutePath());
    Scanner input = new Scanner(file);
 }
}

input.txt is in the same package, same folder and everything. I'm confused :(

© Stack Overflow or respective owner

Related posts about java