黑马程序员技术交流社区

标题: 通过类加载器获得Properites怎么没获取到? [打印本页]

作者: My_Android    时间: 2016-6-2 19:58
标题: 通过类加载器获得Properites怎么没获取到?
  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容器这章, 视频老师的可以运行,我的怎么不可以,来个会得大神




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2