1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

working directory in web application

Discussion in 'Java' started by Juuno, May 4, 2009.

  1. Juuno

    Juuno New Member

    Feb 3, 2009
    Likes Received:
    Trophy Points:
    I have my Java project, say in C:\User\Workspace\myApplication
    And there’s an xml file in that folder: C:\User\Workspace\myApplication\myXML.xml

    And in my java program, I will take that xml file to retrieve information. So, I need to call it from my program. And now I am loading that file like:
    File xmlfile = new File(“C:\\User\\Workspace\\myApplication\\myXML.xml”)

    And I know that it’s not a good way to load a file using directly the absolute path. So, I try to call it from my program dynamically. Here, my program is web application. And I use Tomcat.

    First, I tried this way:

    File directory = new File(“.”);
    String loc = directory.getCanonicalPath();
    File xmlfile = new File(loc + “myXML.xml”);

    And, second I tried using: System.getProperty(“user.dir”);

    Both first and second way give me the same result. When I tried to test those methods as Java application, they both gave me the path : C: \User\Workspace\myApplication

    But when I tried to put it in my program which accepts input from JSP and run on server, then the result path is: C:\Eclipse. So, there’s an error that the system cannot find the file.

    Why it cannot find the actual path?
    And how can I do it to load that xml file into my Java program.

    Any reply would be greatly appreciated.
  2. nimesh

    nimesh New Member

    Apr 13, 2009
    Likes Received:
    Trophy Points:
    Oracle Apps Admin
    Home Page:

Share This Page