第一种方法:用io流实现配置文件的加载
这种方法配置文件需要放在工程项目下跟目录下
<pre name="code" class="java"><pre name="code" class="java">
/** 从配置文件总读取配置内容 **/
InputStream ips=new FileInputStream("config.properties");
Properties props=new Properties();
props.load(ips);
/** 从配置文件中读取相应的值 **/
String classname=props.getProperty("classname");
第二种方法:使用类加载器实现配置文件的加载
这种方法配置文件需要放在classpath指定的目录下
/** 使用类加载器的方式加载配置文件 **/
InputStream ips=HashTest.class.getClassLoader().getResourceAsStream("com/bbp/test/config.properties");
/** 使用类内部的getResourceAsStream实现 **/
InputStream ips=HashTest.class.getResourceAsStream("config.properties");
InputStream ips=HashTest.class.getResourceAsStream("resouces/config.properties");
InputStream ips=HashTest.class.getResourceAsStream("/com/bbp/test/resouces/config.properties");