【发布时间】:2014-08-25 10:20:26
【问题描述】:
在我当前的应用程序中,我需要维护一个config.properties 文件,并且我需要从这个属性文件中获取我的java 文件中的数据。我已将属性文件和访问这些属性文件的ConfigUtil.java 放置在同一位置。但是当我运行应用程序时,它会给出FileNotFoundException。
当两者都在同一个文件夹中时,我无法理解为什么不加载属性文件。
我的 ConfigUtils.java 代码是:
public class ConfigUtil {
private Properties properties;
InputStream inputStream = null;
public Properties getUrl(){
properties = new Properties();
try {
inputStream = new FileInputStream("config.properties");
properties.load(inputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(inputStream != null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return properties;
}
}
和 config.properties 文件也在同一个文件夹中
config.properties 的位置是:
/app/src/main/java/config.properties
ConfigUtil.java 的位置是:
/app/src/main/java.configutils.java
【问题讨论】:
-
可以发一下对应的代码吗?
-
从以下链接获取完整的简短示例程序。 stackoverflow.com/a/29863387/3829818