jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext" Watch "ServletContext" New topic


Ranch Hand

Joined: Oct 09, 2003
Posts: 517

Can anyone give me the detailed explanation of

' getResourceAsStream(java.lang.String path) ' method?

How to call this method?


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

From the API:


public java.io.InputStream getResourceAsStream(java.lang.String path)Returns the resource located at the named path as an InputStream object.
The data in the InputStream can be of any type or length. The path must be specified according to the rules given in getResource. This method returns null if no resource exists at the specified path.

Meta-information such as content length and content type that is available via getResource method is lost when using this method.

The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource.

This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet containers to make a resource available to a servlet from any location, without using a class loader.

path - a String specifying the path to the resource
the InputStream returned to the servlet, or null if no resource exists at the specified path

sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Given a path it will return you InputStream. It is same as getResource().openStream().


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
I agree. Here's the link: http://aspose.com/file-tools
subject: ServletContext
It's not a secret anymore!