-
JAR file paths
Hi,
I have some classes and text files in the same directory contained in a package. I ultimately want to run my program from a jar but right now I cannot seem to access the text files from inside the package.
My classes can't find the text files when I use FileReader even though they are in the same directory. I am not sure what I can do to fix the path issue. Can someone help me?
-
If the text files will be in the Jar file, then don't access them as files but rather as resources. I'm not sure where in the tutorials this is found, but if you search the Sun Java tutorials you'll find a section on this.
-
I tried:
Code:
InputStream b = FileIO.class.getClass().getResourceAsStream(fileName);
try {
//FileReader a = new FileReader(getPath(fileName));
InputStreamReader a = new InputStreamReader(b);
With the same result, null pointer.
-
Where is the data file located in relation to the class files?
-
The classes are in the same package/same directory.
-
Not the classes -- where is the data file?
-
This is what the jar looks like:
cs235/
cs235/javaskills/
cs235/Main.class
cs235/javaskills/TestDriver.class
cs235/javaskills/test1.txt
cs235/javaskills/test2.txt
cs235/javaskills/test3.txt
cs235/javaskills/test4.txt
I am trying to access the text files from TestDriver