getResourceAsStream « Development « Java Data Type Q&A

1. getClass().getClassLoader().getResourceAsStream is throwing a NullPointerException

In Java How could getClass().getClassLoader() return null?

  • The jar the 'class' is located in is NOT located under common/lib.
  • The jar is NOT being boostrap-loaded.
The ClassLoader for all classes within the jar is ...

2. Class.getResource(String) and Class.getResourceAsStream(String)

-------------------------------------- Hi, I have a question about the getResource(String) and getResourceAsStream(String) methods in the Class class. What exacty are the "resources"? Why is the return of getResource(String) a URL? Thanks. -------------------------------------------- Hi, Resource is some data like images, text... that can accessed by the class code. It returns the URL for reading the resource. I haven't tried these methods, so I ...

3. getResourceAsStream returning null

4. getResourceAsStream i get null.

5. .getResourceAsStream null

Are you trying to load the resource from a jar? In that case, the String should probably be something like "/WEB-INF/classes/". If the resource is not in a jar, or in a location that is relative to the class file, you should probably use the Path class to get access to the resource.

6. getResource returns null but getResourceAsStream work.. pls help.

Hi, I have a web application deployed on a web logic server. I need to read a custom xml file from the public_html\WEB-INF folder. input = ctx.getResourceAsStream("WEB-INF/myfile.xml"); // works fine try { URL u = ctx.getResource("WEB-INF/myfile.xml"); // return null. Any idea why the url is not working? 2) Is there any way I can read the file outside the servlet context? ...

7. getResourceAsStream retrive null

A quote from the API doc The path must begin with a "/" and is interpreted as relative to the current context root. You can't use that method to get a file, unless that file exists under the context root of the servlet, use a normal FileInputStream and replace "\" with either "/" or " ". Edit: Or better yet, place ...