【发布时间】:2012-04-19 21:09:19
【问题描述】:
我正在尝试加载属性文件。
我的属性文件与我要加载的类在同一目录中。
示例:
package com.classes.internal;
public class ClassA {
private static String PFILE = "config.properties";
private static void methodA(){
//do stuff
Properties properties = null;
try{
properties = new Properties();
properties.load(new FileInputStream(PFILE));
//properties.load(new ClassA().getClass().getResourceAsStream(PFILE)); --> Does not work either
}catch(Exception e){
e.printStackTrace();
}
}
还有config.properties 文件在 com\classes\internal 目录中
但我得到一个FileNotFoundException 或java.lang.NullPointerException(如果使用注释掉的行而不是第一行)
我在这里做错了什么?我有什么误解?
【问题讨论】:
-
属性文件相对于你的类路径在哪里?
-
与
ClassA在同一目录下
标签: java file properties properties-file