I have an Eclipse project:
myProject/
|--src/
| |--MyClass.java
|
|--bin/
|--MyClass.class
|--data.dat
MyClass
reads from data.dat
. When I edit MyClass.java
and run using :Java
from within vim
, I get a bunch of errors:
java.io.FileNotFoundException: data.dat (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
If I navigate to myProject/bin
and run the classes there using java MyClass
, I'm able to read the data.dat
file.
Where do I set the location of the files I'm trying to open so that they're relative to the compiled Java, not relative to my *.java
files? It doesn't seem to be in the .classpath
file.
As a secondary question: I'm having issues finding the answer to this because I don't quite know what to search for. java runtime file locations
doesn't work. What keywords describe this problem so I can find the answer for myself?
This might be because the default path isn't the bin folder but the project folder itself. Try to move your file to the project folder or change its path within the program.
You could also pass the file via commandline arguments but this can cause some other problems as you might already know.