Java IO流 用类加载器的方式管理资源和配置文件
2015-05-23 22:39
507 查看
package test; import java.io.FileInputStream; import java.io.InputStream; import java.util.Collection; import java.util.Properties; class Point { int x, y; @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + x; result = prime * result + y; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Point other = (Point) obj; if (x != other.x) return false; if (y != other.y) return false; return true; } public Point(int x, int y) { super(); this.x = x; this.y = y; } } //用类加载器 public class Test { public static void main(String[] args) throws Exception { //InputStream ips = new FileInputStream("config.properties"); InputStream ips = Point.class.getClassLoader().getResourceAsStream("test/config.properties"); Properties props = new Properties(); props.load(ips); ips.close(); String className = props.getProperty("className"); Collection collection = (Collection)Class.forName(className).newInstance(); Point pt1 = new Point(1, 1); Point pt2 = new Point(2, 3); Point pt3 = new Point(1, 1); collection.add(pt1); collection.add(pt2); collection.add(pt3); System.out.println(collection.size()); } }
配置文件: test/config.properties
配置文件内容:
className=java.util.ArrayList
相关文章推荐
- 黑马程序员_学习笔记8用类加载器的方式管理资源和配置文件及类加载器的总结
- 用类加载器的方式管理资源和配置文件
- 用类加载器的方式管理资源和配置文件
- 用类加载器的方式管理资源和配置文件
- 28 用类加载器的方式管理资源和配置文件
- 黑马程序员_用类加载器的方式管理资源和配置文件简单介绍
- 类加载器的方式管理资源和配置文件/JavaBean/重构_内省的简单应用
- 反射应用之用类加载器的方式管理资源和配置文件
- 用类加载器的方式管理资源和配置文件
- 黑马程序员--用类加载器的方式管理资源和配置文件
- 用类加载器的方式管理资源和配置文件
- 黑马程序员---用类加载器的方式管理资源和配置文件
- Java类加载器之管理资源和配置文件
- mysq多实例安装和管理 [一] -- 多配置文件方式安装管理
- Linux下配置Gnome的文件打开方式 & 开始菜单管理
- spring的事务管理(配置文件方式和注解方式实现、转账环境搭建)
- 前端资源多个产品整站一键打包&包版本管理(二)——如何在bower的配置文件加上注释
- Spring中bean管理-配置文件和注解方式混合使用
- 8.4.6: Spring的AOP---基于XML配置文件的管理方式
- spring框架的学习(二)——Spring的bean管理(xml配置文件方式)