...

View Full Version : Compiles, Doesn't run



holycow02
04-08-2008, 03:12 AM
This code throws a FileNotFoundException. The file, "primary.input" is in the project folder which is in the same directory as all of the class files and java files.


package proj3;
import java.util.*;
import java.io.*;



class Main
{

public static void main(String[]args) throws FileNotFoundException
{
File fl = new File("primary.input");
FileReader f = new FileReader(fl);
BufferedReader br = new BufferedReader(f);
Stackz s;
try
{
while(br.ready())
{
String theString = br.readLine();
s = new Stackz(theString);
}
}
catch(IOException e){}
}

}


and here is the error the runtime gets:
----jGRASP exec: java proj3.Main

Exception in thread "main" java.io.FileNotFoundException: primary.input (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at proj3.Main.main(Main.java:13)

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


I can give the other classes if they are needed, so let me know if that will help.

Thanks

Aradon
04-08-2008, 05:06 AM
Can you please list your directory structure, starting from the place where you are running the java program. (including files)

holycow02
04-08-2008, 03:54 PM
Here is the directory path:

C:\Documents and Settings\Pat\My Documents\Class ****\CSci341\proj3

everything is in the the proj3 directory, class and java files, as with the input file

_Aerospace_Eng_
04-08-2008, 07:38 PM
And you are sure the file is called primary.input and NOT primary.input.txt?

holycow02
04-08-2008, 08:13 PM
yes the file is called primary.input I took it directly from my teachers files off of our server...and the projects before have all had the exact same file input name. And so far, the projects from before were in perl and they all worked.

This just doesn't make any sense.


One of my friends thinks it might have something to do with the packaging. I'm not sure since the file is in the package directory

Aradon
04-08-2008, 10:30 PM
try putting the file one directory back and see if it will pick it up then. If that doesn't work then you need need to do something like this:



File f = new File("primary.input");
System.out.println(f.getAbsolutePath());



Let us know what it prints out. I have a suspicion on what it is but I'd like to have that printed out before I say.

holycow02
04-08-2008, 10:55 PM
This is what it prints:
C:\Documents and Settings\Pat\My Documents\Class ****\CSci341\primary.input

after I moved it up one directory.

Now im getting a nullpointerexception which is something with my array so I think you fixed it.

Thanks a bunch



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum