然而,一般,我喜歡把web的配置文件放到WEB-INF里,和web.xml 文件放在一起,如果用getResourcesAsStream()肯定是不行了。
仔細(xì)想了一下,找到一個(gè)變通的方法:
????????try{
????????????
????????????String?url?=?this.getClass().getResource("").getPath().replaceAll("%20",?"?");
????????????String?path?=?url.substring(0,?url.indexOf("WEB-INF"))?+?"WEB-INF/config.properties";
????????????Properties?config?=?new?Properties();
??????????? config.load(new FileInputStream(path));
????????????System.out.println(config.getProperty("dbDriver"));
????????}
????????catch(Exception?e){
????????????e.printStackTrace();
????????}
????????????
????????????String?url?=?this.getClass().getResource("").getPath().replaceAll("%20",?"?");
????????????String?path?=?url.substring(0,?url.indexOf("WEB-INF"))?+?"WEB-INF/config.properties";
????????????Properties?config?=?new?Properties();
??????????? config.load(new FileInputStream(path));
????????????System.out.println(config.getProperty("dbDriver"));
????????}
????????catch(Exception?e){
????????????e.printStackTrace();
????????}
這樣,就可以把配置文件放到任意位置了~~~~