[英]“java.net.UnknownHostException” occur when read mybatis xml file
[英]File not found error occur when read property file in java
我在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();
}
但我得到以下错误
java.io.FileNotFoundException: (The system cannot find the path specified)
请让我知道如何获得此属性文件。
试试吧
prop.load(getClass().getResourceAsStream("resources/common/configure/commonData.properties"));
程序试图在相对于运行它的位置指定的路径中找到“commonData.properties”。 提供正确的相对路径或配置文件的完整路径可能会解决此问题。
使用绝对文件路径。 打印完整路径,您将能够发现您的问题。
或者,使用getClass().getResourceAsStream()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.