[EMAIL PROTECTED] (Brett G. Palmer) writes:
> What is the best way to read a file from a Context in Tomcat?  I know I can
> get the context path from the "getContextPath()" method, but most file
> stream APIs require a full path.  There most be a clean way to accomplish
> this without hard coding any directory path info.

I have used the following to read the contents of a file from another
context.

    ServletContext ctx = application.getContext( "/pages" );
    InputStream is = ctx.getResourceAsStream( "/agreement.txt" );

To read from another context (as I'm doing) does require that the context
has been set up as "crossContext".

By using "getResourceAsStream()", this should even work in containers
that don't unpack the WAR file to the filesystem.

-- 
 `O O'  | [EMAIL PROTECTED]
// ^ \\ | http://www.pyrites.org.uk/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to