Carig,
I tried this it does not work. I can't get the stream.
I have a property file in the classes directory- where
I all my classes are. My code is:
MyClass thisInstance  = new MyClass();
InputStream stream =
thisInstance.getClass().getResourceAsStream(propFile);
if ( stream != null) {
  props.load(stream);
  stream.close();
}else System.out.println("The stream null");

Thanks
Sanjay


--- "Craig R. McClanahan" <[EMAIL PROTECTED]> wrote:
> 
> 
> On Wed, 3 Apr 2002, Sanjay Bahal wrote:
> 
> > Date: Wed, 3 Apr 2002 12:00:17 -0800 (PST)
> > From: Sanjay Bahal <[EMAIL PROTECTED]>
> > Reply-To: Tomcat Users List
> <[EMAIL PROTECTED]>
> > To: Tomcat Users List
> <[EMAIL PROTECTED]>
> > Subject: RE: Working Directory
> >
> > Thanks Mark & Craig.
> > My situation is slightly different. I am trying to
> > read the property file from a Java class on the
> > server(not the servlet). I would think there would
> be
> > a way around to do this- else I can work around to
> > pass a param to the helper class.
> 
> Consider using
> getClass().getResourceAsStream("myprops.properties")
> for
> this kind of purpose.  This looks for
> "myprops.properties" on your class
> path, and loads it from wherever the classes
> themselves are found (either
> an unpacked directory or a JAR file).
> 
> > Thanks
> > Sanjay
> 
> Craig
> 
> 
> > --- "Craig R. McClanahan" <[EMAIL PROTECTED]>
> wrote:
> > >
> > >
> > > On Wed, 3 Apr 2002, Wagoner, Mark wrote:
> > >
> > > > Date: Wed, 3 Apr 2002 11:38:31 -0500
> > > > From: "Wagoner, Mark"
> <[EMAIL PROTECTED]>
> > > > Reply-To: Tomcat Users List
> > > <[EMAIL PROTECTED]>
> > > > To: 'Tomcat Users List'
> > > <[EMAIL PROTECTED]>
> > > > Subject: RE: Working Directory
> > > >
> > > > I place my properties files in the WEB-INF
> > > directory and do the following to
> > > > find them -
> > > >
> > > > String webInfFolder =
> > > getServletContext().getRealPath("/WEB-INF")
> > > >
> > >
> > > This only works if the app is run from an
> unpacked
> > > directory, which is not
> > > guaranteed to be portable (not every server
> supports
> > > running this way).
> > > The best way to read a properties file is to put
> it
> > > in the WEB-INF
> > > subdirectory and use something like:
> > >
> > >   Properties props = new Properties();
> > >   InputStream stream =
> > >
> > >
> >
>
getServletContext().getResourceAsStream("/WEB-INF/myprops.properties");
> > >   props.load(stream);
> > >   stream.close();
> > >
> > > which is guaranteed to be portable to any
> server.
> > >
> > > Craig
> > >
> > >
> > > > -----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]>
> > >
> >
> >
> > __________________________________________________
> > 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]>
> 


__________________________________________________
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]>

Reply via email to