- 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容器这章, 视频老师的可以运行,我的怎么不可以,来个会得大神 |
|