【发布时间】:2014-04-29 12:54:23
【问题描述】:
Eclipse/Linux - Java Web 应用程序。
我在我的项目中添加了一个名为 dao.properties 的文件。我把它放在一个包里:com.cdp.dao。我使用这个文件的类在同一个包中。 当我尝试加载它时,我有一个
java.io.FileNotFoundException
/myproject/src/com/cdp/dao/dao.properties (No such file or directory) OR
dao.properties (No such file or directory)
这是我的代码:
Properties prop;
FileInputStream fis;
File file = new File("/myproject/src/com/cdp/dao/dao.properties");
//File file = new File("dao.properties"); doesn't work either
try {
prop = new Properties();
fis = new FileInputStream(file);
prop.load(fis);
dbUrl = prop.getProperty("dbUrl");
user = prop.getProperty("user");
pwd = prop.getProperty("pwd");
driver = prop.getProperty("driver");
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
【问题讨论】:
-
只需在 File 构造函数中使用 com/cdp/dao/dao.properties..并告诉我
-
它没有用。当我提到绝对路径名时它会起作用。猜猜我不明白构造函数例外的字符串路径。现在可以了,谢谢。
标签: eclipse filenotfoundexception fileinputstream