from: http://java.sun.com/j2se/1.3/docs/api/index.html:
getResourceAsStream public InputStream getResourceAsStream(String name)Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class. This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResourceAsStream. Parameters: name - name of the desired resource Returns: a java.io.InputStream object. Since: JDK1.1 See Also: ClassLoader -----Original Message----- From: Jacob Kjome [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 03, 2002 7:41 PM To: Tomcat Users List Subject: RE: Working Directory That might work in most cases, but it won't find the file in a container that doesn't expand the .war archive. The following will read it whether in a directory structure or in a .war archive: InputStream is = getServletContext().getResourceAsStream("/WEB-INF/myApp.properties"); If the file exists in the same package as the class, you can load it like this: InputStream is = this.getClass().getResourceAsStream("myApp.properties"); I would think you could also do this to find it in the classes directory: InputStream is = this.getClass().getClassLoader().getResourceAsStream("myApp.properties"); All those methods are independent of the filesystem. Jake At 11:38 AM 4/3/2002 -0500, you wrote: >I place my properties files in the WEB-INF directory and do the following to >find them - > >String webInfFolder = getServletContext().getRealPath("/WEB-INF") > >-----Original Message----- >From: Sanjay Bahal [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, April 03, 2002 11:34 AM >To: tomcat >Subject: Working Directory > > >I am trying to read a properties file from my servlet. >It always comes back saying file not found. I have >tried placing the file in >classes/web-inf/context-path. Ideally I would like to >lace it in my classes directory- How do I achieve it. >Thanks >Sanjay > >__________________________________________________ >Do You Yahoo!? >Yahoo! Tax Center - online filing with TurboTax >http://taxes.yahoo.com/ > >-- >To unsubscribe: <mailto:[EMAIL PROTECTED]> >For additional commands: <mailto:[EMAIL PROTECTED]> >Troubles with the list: <mailto:[EMAIL PROTECTED]> > >-- >To unsubscribe: <mailto:[EMAIL PROTECTED]> >For additional commands: <mailto:[EMAIL PROTECTED]> >Troubles with the list: <mailto:[EMAIL PROTECTED]> -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>
