crysoberil
crysoberil

Reputation: 271

Eclipse dynamic web project : where should I put resource files

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

Answers (2)

M Sach
M Sach

Reputation: 34424

getResourceAsStream searches for the file on the classpath

   InputStream stream = this.getClass().getClassLoader().getResourceAsStream("your pdf file");

Upvotes: 0

celezar
celezar

Reputation: 442

You could use

this.getClass().getResourceAsStream("mypdf.pdf");

if the file is in directory where your class is.

Upvotes: 1

Related Questions