tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Longson, Robert" <robert_long...@standardandpoors.com>
Subject RE: io.File relative path constructor
Date Wed, 07 Sep 2005 10:10:18 GMT
Paul,

If the file is in a JAR you can generate a URL to access it.

either something along the lines of

ServletContext context = getServletConfig().getServletContext();
URL url = context.getResource("/path/file.xml");

or alternatively using the class loader

URL url = getClass().getResource("/path/file.xml");

Best regards

Robert

-----Original Message-----
From: Paul Wallace [mailto:pwallace@twowaytv.com.au]
Sent: 07 September 2005 07:51
To: Tomcat Developers List
Subject: io.File relative path constructor


 
Hi,
	A should-be easy one - I do not wish to define an absolute path
to a File as it will packaged in a JAR, therefore its path will change.
How do I construct a File relative to my src root, something like File
file = new File("/path/myFile.xml");? I tried passing in a URL, URI but
am getting:

Exception in thread "main" java.lang.IllegalArgumentException: URI is
not hierarchical

when I jar and run it. Am using Win XP + Java 1.5.

Thanks

Paul.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org 
  
--------------------------------------------------------
 
The information contained in this message is intended only for the recipient, and may be a
confidential attorney-client communication or may otherwise be privileged and confidential
and protected from disclosure. If the reader of this message is not the intended recipient,
or an employee or agent responsible for delivering this message to the intended recipient,
please be aware that any dissemination or copying of this communication is strictly prohibited.
If you have received this communication in error, please immediately notify us by replying
to the message and deleting it from your computer. 
--------------------------------------------------------
 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message