FileNotFoundException Issue

I have a program that needs to read another file while running. When I run the program I get a FileNotFoundException thrown back. I have placed a copy of the file needing to be read, "balls.nff", within the classes folder of my compiled program (also my CLASSPATH). Also, I have set proper file permissions (read, write) to this file. Do I have my file "balls.nff" in the right directory. How come it can't find it? Where is it looking for it? Can anyone help?

The relative portion of the source code is as follows:

staticvoid ReadFile(String file)

{

try{

if (file ==null)

file ="balls.nff";

FileInputStream s =new FileInputStream(file);

StreamTokenizer d =new StreamTokenizer(new InputStreamReader(s));

d.commentChar('#');

int t;

while (d.nextToken() != StreamTokenizer.TT_EOF)

{

ReadDescriptor(d);

}

}catch (Exception e){

System.out.println ("ReadFile Error: " + e);

e.printStackTrace();

System.exit(1);

}

}

After compiling and running the program I get the following:

ReadFile Error: java.io.FileNotFoundException: balls.nff (No such file or directory)

java.io.FileNotFoundException : balls.nff (No such file or directory)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(FileInputStream.java:106)

at java.io.FileInputStream.<init>( FileInputStream.java:66)

at Raytracer_class_impl.ReadFile(\Raytracer_class_impl.java)

at Raytracer_class_impl.main(\Raytracer_class_impl.java)

at Raytracer_class_impl_KStub.main(Raytracer_class_impl_KStub.java)

at Raytracer.main(\Raytracer.java)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at jp.lang.JavaParty.invokeMain(JavaParty.java:207)

at jp.lang.JavaParty.mainExec(JavaParty.java:177)

at jp.lang.JavaParty.main(JavaParty.java:139)

[2847 byte] By [SamRNa] at [2007-11-27 3:03:06]
# 1
hir u set classpath clearly...try thisset classpath=.;%classpath%;
drvijayy2k2a at 2007-7-12 3:46:26 > top of Java-index,Java Essentials,New To Java...
# 2

Opeing a file using a relative filepath (i.e. not a complete path) will attempt to locate the file using the Current Working Directory (the user.dir System Property), which is completely different from the Classpath. If you wish to open a file located on the classpath use the "getResourceAsStream" method from "Class". Read the API for this method.

masijade.a at 2007-7-12 3:46:26 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks! That solved it!
SamRNa at 2007-7-12 3:46:26 > top of Java-index,Java Essentials,New To Java...