黑马程序员技术交流社区
标题:
通过类加载器获得Properites怎么没获取到?
[打印本页]
作者:
My_Android
时间:
2016-6-2 19:58
标题:
通过类加载器获得Properites怎么没获取到?
package com.bjsxt.others.properties;
import java.io.IOException;
import java.util.Properties;
/**
* 使用类相对路径读取配置文件
*
*/
public class Demo04 {
public static void main(String[] args) throws IOException {
Properties pro = new Properties();
//类相对路径的 “/“ 指的是当前 bin 目录
pro.load(Demo04.class.getResourceAsStream("/com/bjsxt/others/properties/db.properties"));
//使用类加载器 "" 值的是当前 bin 目录
// pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(""));
System.out.println(pro.getProperty("user", "没有"));
}
}
复制代码
刚刚学到Properites容器这章, 视频老师的可以运行,我的怎么不可以,来个会得大神
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2