FileNotFoundException via Scanner
Hello,
This block of code:
public Member parseFile(String file_loc) throws FileNotFoundException{
File memberFile = new File(file_loc);
LinkedList stackList = new LinkedList();
Scanner s = new Scanner(memberFile);
while (s.hasNextLine()){
stackList.addLast(s.nextLine());
}
Produce this error:
java.io.FileNotFoundException: PA1-exampleData (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at a1.InformationParser.parseFile(InformationParser.j ava:37)
PA1-exampleData is a file that is passed to this procedure (within the class InformationParser) through the main of another class.
I am executing this is the same directory of the file yet the error indicates that the it cannot find the file.
This error occurs on line 37 of InformationParser, at the line reading " Scanner s = new Scanner(memberFile); ".
Am I missing something here?
Re: FileNotFoundException via Scanner
You can use File.getAbsolutePath() to get the full path the JVM will use to locate the file. Print the absolute path out just before the error happens. Is it what you expect?
Re: FileNotFoundException via Scanner
Adding System.out.println(memberFile.getAbsolutePath()); before the error causes it to display the same error message, but no path is printed before it occurs. Odd.
Re: FileNotFoundException via Scanner
Did you check the line numbers in the Exception? If you added a line and compiled your code the line numbers should at least have increased by 1.
Re: FileNotFoundException via Scanner
Yes, the error now happens on line 38 instead of line 37.
Re: FileNotFoundException via Scanner
Maybe you should change that line to:
Code java:
System.out.println("****\n\n\n****LOOKIT THIS FILE!!!! '" + memberFile.getAbsolutePath() + "' ****\n\n\n\n **** CAN YOU SEE ME NOW?????\n\n\n\n****");
There's always a chance that getAbsolutePath() is returning something very short.
Re: FileNotFoundException via Scanner
Nevermind, I just found out that I'm in the wrong directory. Thumbsup for Sean4u anyway :)