简体   繁体   中英

File not found error occur when read property file in java

i create the property file under package of resources/common/configure/

then i create the 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 property file.

试试吧

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

The program tries to find the "commonData.properties" at a path specified relative to where you are running it. Providing a correct relative path or full path of configuration file might solve the issue.

Use absolute file paths. Print the full path and you'll be able to spot your problem.

Alternatively, use getClass().getResourceAsStream() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM