Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

settign relative path in servlet?

843842Sep 21 2009 — edited Sep 21 2009
Hi people,
I'm new to the java world and have a very basic question. I have implemented a servlet which is accessing a file (part of the web project) using absolute path:
File fofile = new File("C:/work/Project/IBNSubscriberServlet/src/com/ibn/util/g7.xsl");
           
FileInputStream file = new FileInputStream(fofile);
      
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new FileInputStream(fofile)));
The above works fine. But what i want to do is to set the path above relative to my project. The above servlet code is in a class file
C:/work/Project/IBNSubscriberServlet/src/com/ibn/util/g7Transformer.java
, which is accessed through a servlet
C:/work/Project/IBNSubscriberServlet/src/com/ibn/servlets/SubscriberServlet.java
. note: "util" and "servlets" folder difference.

So my question is how can i set the file path "relative" so that when i place this project on some other machine (along with the g7.xsl), the file is still accessible.

On my changing the file path to just
g7.xsl
instead of absolute path
File fofile = new File("C:/work/Project/IBNSubscriberServlet/src/com/ibn/util/g7.xsl");
it does not work.

Please help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 19 2009
Added on Sep 21 2009
16 comments
441 views