Search code examples
javapropertiesfileinputstream

Path not found for a property file in Web application?


My Property file location is WebRoot/WEB-INF/Test/property files/Question.properties

Now I want to load the property file using FileInputStream. So I wrote the below code.

Properties pr = new Properties();
pr.load(new FileInputStream("WebRoot/WEB-INF/Test/property files/Question.properties"));

By the above code I got java.io.FileNotFoundException.I am using myeclipse for my development. Can any one suggest the path to read my properties.


Solution

  • You are opening it relative to the current directory. Do you know what the current directory is? Try creating a:

    File f = new File("WebRoot/WEB-INF/Test/property files/Question.properties");
    

    Then printing or debug the absolute path of the File object. This will tell you what file you are actually trying to open (i.e. full path).

    However, if you are trying to open a 'resource' bundled with your web app (as suggested by /WEB-INF/ being in the path) this is probably not a good way to do it. One alternative is to build your 'resource' into one of your application's .jar files.

    See here, for a related answer: Refer to a web page inside a jar file