----- Original Message -----
From: "Stephan Wiesner" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Wednesday, December 19, 2001 9:36 AM
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.
>[...]



* java.io.InputStream and/or java.util.Properties
- InputStream is =
   this.getClass().getClassLoader().getResourceAsStream("xyz.properties");
 - InputStream is =
   this.getClass().getResourceAsStream("testApp.properties");
- InputStream is =

Thread.currentThread().getContextClassLoader().getResourceAsStream("myservle
t.conf");
- InputStream is =
   getServletContext().getResourceAsStream("/WEB-INF/xyz.properties");

-  Properties props = new Properties();
    props.load(is);
    is.close();

* use java.util.ResourceBundle

* use file-system directly


//haha :-)
Bo
Dec.19, 2001



--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to