Java's getResourceAsStream() is always returning null

Posted by Andreas Grech on Stack Overflow See other posts from Stack Overflow or by Andreas Grech
Published on 2010-05-09T09:18:31Z Indexed on 2010/05/09 9:28 UTC
Read the original article Hit count: 161

Filed under:
|
|
|

I have the following structure in a Java Web Application:

TheProject
  -- [Web Pages]
  -- -- [WEB-INF]
  -- -- -- abc.txt
  -- -- index.jsp
  -- [Source Packages]
  -- -- [wservices]
  -- -- -- WS.java

In WS.java, I am using the following code in a Web Method:

InputStream fstream = this.getClass().getResourceAsStream("abc.txt");

But it is always returning a null. I need to read from that file, and I read that if you put the files in WEB-INF, you can access them with getResourceAsStream, yet the method is always returning a null.

Any ideas of what I may be doing wrong?

© Stack Overflow or respective owner

Related posts about java

Related posts about web-services