I have following structure in jar
myjar.jar -> com -> MYProgram.class
-> file.txt
In MYProgram i am trying to do:
getClass().getResourceAsStream("../file.txt")
I am getting NullpointerException when i try to read the inputstream..
Where is it going wrong ?
Either use
or
(
ClassLoader.getResourceAsStreamalways takes an “absolute” resource name.)I don’t believe navigating up the “directory hierarchy” works in
getResourceAsStream– the path either has to be relative to the given class but without navigating back up the tree, or it has to be absolute to start with.