日期:2014-05-20 浏览次数:20897 次
Properties prop = new Properties();
prop.load(new FileInputStream("xxxx.properties"));
------解决方案--------------------
不再项目目录,楼上这个
Properties prop = new Properties();
prop.load(new FileInputStream("xxxx.properties"));
要用绝对路径了把,这样移植性不高哦,最好是放在src下,它也是源代码的一部分吗。
------解决方案--------------------
放在classpath能找到的地方,然后相对于根写相对路径,这样比较好,也便于发布,比如放在某个包里。
------解决方案--------------------
Properties prop = new Properties();
prop.load(new FileInputStream("xxxx.properties"));
这个如果不在项目目录下,可以用ls这种方法:
测试了一下,可以用。properties文件在项目的根目录下。
public class MyUserDetailService {
public static void main(String[] args){
InputStream in = MyUserDetailService.class.getClassLoader().getResourceAsStream("..\\db_config.properties");
Properties pro = new Properties();
try {
pro.load(in);
System.out.println(pro.getProperty("driver"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
------解决方案--------------------