The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

scanner problems

i'm trying to use

Scanner input = new Scanner(new File("wherefits.dat"));

to load a file, but i get the exception

Exception in thread "main" java.io.FileNotFoundException: wherefits.dat (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
at java.util.Scanner.<init>(Scanner.java:636)
at blahblahblah.wherefits.main(wherefits.java:11)

Re: scanner problems

I would say you should check all aspects of the location and name of the file.

You should find the file and check the name for case and any other minor details. I'm not sure about Eclipse, but with my IDE, you should check that the file is in the same folder as your .class files. The .class files are what will run when you test the program, it will search that directory for the file.

If the problem still exists after you do those checks, you should check the ability for the program to read the file. It probably isnt an issue, but it couldnt hurt. The easiest way to do this would be by create a JFileChooser and selecting the file manually. Here is the code for that so you don't have to worry about learning the GUI aspect yet(I have not tested it, but I've done this enough that I'm pretty sure I have it down pack. If there are any problems, tell me and Ill fix it):

When the JFileChooser opens, go to the file, select it, and press Open. This should Open the file and print out the file's path. If there are any exceptions thrown, they will print to the console instead. If there is an error, please respond with the error so we can help from there.

Re: scanner problems

Another very simple minded way, when all else fails, to find where a system like an IDE looks for files is to create many files with the same name and put one in each folder that could be looked in and have the first line of the file say what folder it is located in. When you execute your program print the first line read from the file which will tell you where the file was read from.