public static Properties getProperties(String name){
InputStream in = ClassLoader.getSystemResourceAsStream("config/"+name+".properties");
Properties properties = new Properties();
try {
properties.load(in);
in.close();
in = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
properties = null;
}
return properties;
}这个方法是我写的一个读取配置文件的方法,在MAIN方法里面测试通过,但是在serlvet里面调用,这个方法总是执行不了,我想是不是资源不够,用个线程来执行还是不行,请大侠们帮忙指点下,小弟不甚感激~~~
路径明显是相对路径....
Properties prop = new Properties();
InputStream in = new FileInputStream(configFilePath);
prop.load(in);
InputStream in = ClassLoader.getSystemResourceAsStream("config/"+name+".properties");
System.out.println(ClassLoader.getSystemResourceAsStream("config/"+name+".properties"));
Properties properties = new Properties();
try {
properties.load(in);
in.close();
in = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
properties = null;
}
return properties;
}
public static void main(String[] args) {
System.out.println("out:"+getProperties("config").getProperty("cacheSize"));
}
结果:out:104857600
servlet中访问应用资源的路径使用绝对路径最好。