一、使用类装载器获取文件配置文件信息: 注意以下两点:1、通过类装载器获取的文件不能太大。2、通过类装载器获取的配置文件信息不能得到修改后的最新信息。
二、使用类装载至获取文件的路径获取配置文件信息:解决了用类加载器的获取文件信息的两个缺点。
public void test1() throws IOException{
URL url=ClassloderTest.class.getClassLoader().getResource("db.properties");
String path=url.getPath();
FileInputStream fis=new FileInputStream(path);
Properties p=new Properties();
p.load(fis);
p.getProperty("DRIVER");
if(fis!=null){
fis.close();
}
}