Reputation: 271
I am trying to make a eclipse dynamic web project. I have tried putting a pdf file in the "WEB-INF" directory of the project. But when I try to obtain a input stream using
InputStream inStream = getServletContext().getResourceAsStream("/WEB-INF/mypdf.pdf");
I get inStream = null
. I also tried putting the mypdf.pdf
file in the directory the class from where I am trying to obtain the input stream and use
InputStream inStream = getServletContext().getResourceAsStream("mypdf.pdf");
again, it returns inStream = null
Any suggestion?
Upvotes: 0
Views: 2791
Reputation: 34424
getResourceAsStream searches for the file on the classpath
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("your pdf file");
Upvotes: 0
Reputation: 442
You could use
this.getClass().getResourceAsStream("mypdf.pdf");
if the file is in directory where your class is.
Upvotes: 1