在java中读取属性文件时发生文件未找到错误

AKZ*_*Zap 4 java properties classpath

我在包的包下创建属性文件 resources/common/configure/

然后我创建代码

    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();
    }
Run Code Online (Sandbox Code Playgroud)

但我得到以下错误

java.io.FileNotFoundException: (The system cannot find the path specified)
Run Code Online (Sandbox Code Playgroud)

请让我知道如何获得此属性文件.

Jig*_*shi 5

试试吧

prop.load(getClass().getResourceAsStream("resources/common/configure/commonData.properties"));
Run Code Online (Sandbox Code Playgroud)