当前位置: 代码迷 >> Web前端 >> web工程停获取properties文件
  详细解决方案

web工程停获取properties文件

热度:148   发布时间:2013-10-05 17:54:48.0
web工程下获取properties文件
String propertiesPath = getClass().getClassLoader().getResource("").getFile();
propertiesPath = propertiesPath.substring(1, propertiesPath.length());
//windows下
InputStream in = new FileInputStream(new File(propertiesPath + "/resource.properties"));
//linux下
//InputStream in = new FileInputStream(new File("/opt/apache-tomcat-6.0.26/webapps/IMS/WEB-INF/classes/resource.properties"));
Properties prop = new Properties();
prop.load(in);
Enumeration e = prop.propertyNames();
while(e.hasMoreElements()){
  String propKey = (String)e.nextElement();
  String propValue = prop.getProperty(propKey);
  propertiesMap.put(propKey, propValue);
}
in.close();
  相关解决方案