/**
* 注:此处一定要用完整的的路径,但完整的路径不是硬编码,而是运算出来的
*/
First:直接读取,文件应放在与java工程相同等级
//InputStream ips = new FileInputStream("config.properties");
Second: //通过获取类加载器来加载文件
//InputStream ips = ReflectTest3.class.getClassLoader().getResourceAsStream("com/onschool/reflect/config.properties");
Third: //相对于同一个包来进行加载子目录下的文件
InputStream ips = ReflectTest3.class.getResourceAsStream("config.properties");
// 定义属性对象
Properties prop = new Properties();
// 从属性文件中读出属性值(其中属性对象为Hashtable)
// 抛出异常为IllegalArgumentException(非法数据异常)和IOException(输入输出异常)
prop.load(ips);