You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Randy Layman <ra...@aswethink.com> on 2001/12/19 14:59:59 UTC
RE: How to find a file from a class with Tomcat
If you only need a stream (and not FileInputStream) you can use
getResouceAsStream, which will return an InputStream, from which you can
create just about any other stream that you want.
Randy
> -----Original Message-----
> From: Stephan Wiesner [mailto:wiesner@werum.de]
> Sent: Wednesday, December 19, 2001 9:36 AM
> To: Tomcat Users List
> Subject: How to find a file from a class with Tomcat
>
>
> I have a Servlet S.java which uses a class C.java (not a
> servlet itself,
> could make it one if I had too).
> C.java needs to read a config file. The problem is that this
> class thinks it
> is in c:/ or wherever I started the tomcat server from. I can use
> this.getClass().getResource(fileName); but that only works with
> Properties.load(), not with a FileInputStream.
> So at the moment I have all my paths hardcoded into the classes and of
> course I don't want that.
>
> My server.xml contains:
> <Context path="/examples"
>
> docBase="d:/jdk1.3/jakarta-tomcat-3.2.3/webapps/examples"
> crossContext="false"
> debug="9"
> reloadable="true" >
> </Context>
>
> And the local web.xml:
> <servlet>
> <servlet-name>hi</servlet-name>
> <servlet-class>HelloWorldExample</servlet-class>
> </servlet>
> <servlet-mapping>
> <servlet-name>hi</servlet-name>
> <url-pattern>/hi/*</url-pattern>
> </servlet-mapping>
>
>
> Any tipp would be appreciated.
>
> Stephan Wiesner
>
>
> --
> To unsubscribe: <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>