Reputation: 400
Always giving Inputstream
is null
in spring boot
application for me.
Below code for getting inputstream object
and image is for my resource file location.
Why I am getting inputstream object
is null
I am not sure.
Is there any issue I am loading this file while running power mock test case
IDataSet dataSet;
InputStream is = ClassLoader.class.getResourceAsStream("/all/testdata.json");
if (dataScript.endsWith(".json")) {
dataSet = new JsonDataSet(is);
}
Upvotes: 0
Views: 1108
Reputation: 13047
Use the system classloader to access resources from the root:
ClassLoader.getSystemResourceAsStream("/all/testdata.json");
Upvotes: 2
Reputation: 36103
If you use:
InputStream is = YourClass.class.getResourceAsStream("/all/testdata.json");
Java looks relative to YourClass for the given file path.
If you use:
InputStream is = YourClass.class.getClassLoader().getResourceAsStream("/all/testdata.json");
Java looks relative from the root of the class path.
So I assume that you are looking for the second option
Upvotes: 0