tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Open a file?
Date Wed, 03 Oct 2001 16:28:00 GMT


On Tue, 2 Oct 2001, Bob Byron wrote:

> Date: Tue, 2 Oct 2001 22:03:37 -0500
> From: Bob Byron <bbyron@radit.com>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org
> Subject: Open a file?
>
> Okay, now I need to open the XML file and I am trying to
> figure out how to do that.  When I try to open the file "file.xml",
> Tomcat 4 is trying to open it relative to "Tomcat\4.0\bin", the
> location of the startup scripts.  I want to know what is the
> Tomcat centric way of opening a file relative to the webapp
> that it is running under?  I hope I have phrased the question
> sufficiently for you to understand what I need to do.  I need
> a different reference point, one that uses the webapp itself
> as a base.
>

If you have a file "file.xml" in the top-level directory of your web app,
open it like this:

  InputStream stream =
	getServletContext().getResourceAsStream("/file.xml");

This will work on all servlet containers (not just Tomcat).  It will also
work when your web app is run directly from a WAR file rather than being
unpacked.

> Thank You,
> Bob Byron
>
>

Craig McClanahan



Mime
View raw message