0

I am trying to access config.xml file from my JAVA program. But its showing me "File Not Found". Here is my project structure. I am using eclipse.

enter image description here

So now I want to read "conf/config-file.xml". How should I do that?
Note:

  • I cannot change project structure.
  • 'conf' and 'bin' they ain't under '/root'.They are under just one common project directory.

Please help Thank you!!

ajduke
  • 4,991
  • 7
  • 36
  • 56
suraj_fale
  • 978
  • 2
  • 21
  • 53
  • 1
    Try get the path of your jar file, maybe [this post][1] will be helpful. [1]: http://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file – Maxi Baez Jun 21 '13 at 01:49

3 Answers3

2

Using "user.dir" property of Java System Variable, you can access your file.

System.getProperty("user.dir") + File.separator + "conf" + File.separator +  "config-file.xml"
Sunil Gulabani
  • 878
  • 1
  • 8
  • 21
1

If you start the java program from Eclipse, the default work directory (current directory) is the project directory like "C:\workspace\myproject"(or /workspace/myproject on Linux). To open the conf/config-file.xml, the following codes should work.

File configFile = new File("conf/config-file.xml");
System.out.println(configFile.getAbsolutePath()); // Just for testing
Pu Gong
  • 176
  • 3
0

not sure but try this>> ../conf/config-file.xml

gjman2
  • 912
  • 17
  • 28