![](/img/trans.png)
[英]“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.