> From: David.Meldrum [mailto:david.meld...@verizon.net] 
> Subject: Re: Path problem
> 
> actually in my case I am trying to read/write from a 
> ContextListenr

It's generally a bad idea to ever *write* into the webapp deployment space.  
You have no guarantee that the space is writable, nor that the container will 
provide any write access.  You're much better off writing to files outside of 
Tomcat's directory structure, where the path can be provided by system 
property, environment variable, <init-param>, or whatever.

> As recommended below, you could use 
> Class.getResourcesStream(), but as I understand it,
> that will give the location of this class under 
> WEB-INF.

Or anywhere else in the webapp's structure; it's not confined to WEB-INF.

> public void contextInitialized(ServletContextEvent event)  {
>     ServletContext sctx = event.getServletContext();
>     String propPath = sctx.getRealPath( 
> "/WEB-INF/resource.properties");
>     FileInputStream inStrm = new FileInputStream(propPath);
>   .....
> }

Using ServletContext.getRealPath() is risky; the container is under no 
obligation to provide access to the underlying file system (think deployment 
via .war file).  Much safer and better to use getResourceAsStream().

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to