File error not found while reading properties file in java

i create the property file in the resources/common/configure/ package

then i create code

  Properties prop = new Properties(); try { //load a properties file prop.load(new FileInputStream("resources/common/configure/commonData.properties")); //get the property value and print it out System.out.println(prop.getProperty("id")); } catch (IOException ex) { ex.printStackTrace(); } 

but I got the following error:

 java.io.FileNotFoundException: (The system cannot find the path specified) 

please let me know how can I get this properties file.

+4
source share
3 answers

Try

 prop.load(getClass().getResourceAsStream("resources/common/configure/commonData.properties")); 
+5
source

The program tries to find "commonData.properties" along the path specified as to where you run it. Providing the correct relative path or full path of the configuration file may solve the problem.

+2
source

Use absolute file paths. Print the full path and you can identify your problem.

Alternatively, use getClass().getResourceAsStream() .

0
source

All Articles