Reputation: 77
Hi I would like to ask why I am getting null value with getResourceAsStream?
Here is the snippet of my code:
I have tried this and it's working.
InputStream ios = new FileInputStream(Constant.DEFAULT_PROFILE_PICTURE);
I just want to know why I'm getting null value when I'm using getResourceAsStream.
InputStream ios = request.getSession().getServletContext().getResourceAsStream(Constant.DEFAULT_PROFILE_PICTURE);
Constant.DEFAULT_PROFILE_PICTURE path is : /home/user/NoImageAvailable.png
Thank you for some inputs!
Upvotes: 0
Views: 1364
Reputation: 379
You are using and Initializing the Resource correctly.
So if it is not working than your file is either not using an relative path to its location inside the Resources folder or isn't at all inside the Resources folder.
If it is not in the Resources folder getResourceAsStream cant access it.
For example: The Structure:
└── src
└── main
├── java
│ └── Main.java // Here you would use the your Resource for example
└── resources
└── NoImageAvailable.png
Constant declaration:
class Constant {
public static final String DEFAULT_PROFILE_PICTURE = "NoImageAvailable.png";
}
If you are using the structure this should work :).
Upvotes: 3