I know what the problem is I just don't know how to fix it.
I access files that are outside of my jar file and usually in an IDE if you put the files in the same directory it operates file and you can access those files by simply typing in the file name, but if you attempt to do the same after it has been compiled I get an expected response of file not found which is my error catcher.
Now how can I make sure the files I am needing to access can always be found relative to where my jar file is?
King Goddard wrote:Now how can I make sure the files I am needing to access can always be found relative to where my jar file is?
How about putting it inside the jar file?
prompt-> jar -tf foo.jar
I put my file bar.txt right beside my class that read it.
My code looks like (not too pretty though)
Eclipse did not want to build the jar for me so I had to build it myself. (Due to my ignorance.)
jar -cef foo\LoadFileFromJar foo.jar foo
And it runs with
java -jar foo.jar foo.LoadFileFromJar
You can also check out the thread Just-Another-Resource.
That means you should set your working directory before you run the jar. But as Jonas says, it's better to put the resources inside the jar as well as the code.