A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

  1. package com.bjsxt.others.properties;

  2. import java.io.IOException;
  3. import java.util.Properties;

  4. /**
  5. * 使用类相对路径读取配置文件
  6. *
  7. */
  8. public class Demo04 {
  9.         public static void main(String[] args) throws IOException {
  10.                 Properties pro = new Properties();
  11.                 //类相对路径的   “/“ 指的是当前 bin 目录
  12.                 pro.load(Demo04.class.getResourceAsStream("/com/bjsxt/others/properties/db.properties"));
  13.                
  14.                 //使用类加载器    "" 值的是当前 bin 目录
  15. //                pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(""));
  16.                 System.out.println(pro.getProperty("user", "没有"));
  17.         }
  18. }
复制代码


刚刚学到Properites容器这章, 视频老师的可以运行,我的怎么不可以,来个会得大神

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马