I am trying to access a file from my project's directory, let's call it
src/main/project/foo/bar.txt
In class MyClass
But when I do:
InputStream is = MyClass.class.getResourceAsStream("bar.txt");
And do anything with the InputStream, e.g.
is.toString();
I get a NullPointerException
I have also tried:
MyClass.class.getResourceAsStream("/bar.txt");
and
MyClass.class.getResourceAsStream("./bar.txt");
Is there something extra I need to do as the file is not in the same package as the class in which I'm calling it? This application is deployed on TomCat, so absolute references to the filepath are impractical.
EDIT: To the person who flagged it as a duplicate of nullpointer, I know what a nullpointer is, obviously it can't find the resource. As to why that is the case, I need help figuring out.