JSP+Java+properties+FileInputStream文件读写,JSP页面读取properties文件

时间:2023-03-09 01:41:39
JSP+Java+properties+FileInputStream文件读写,JSP页面读取properties文件
String realPath = request.getRealPath("WEB-INF/classes/com/properties/devicetype.properties");

以上为获取路径的最正确做法,因此,properties可以放在com包下,或者src目录下。

        Properties props = new Properties();
ArrayList al = new ArrayList();
try {
InputStream in = new BufferedInputStream (new FileInputStream(realPath));
props.load(in);
Enumeration en = props.propertyNames(); while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String Property = props.getProperty (key);
al.add(Property);
//System.out.println(key+Property);
}
} catch (Exception e) {
e.printStackTrace();
}

以上代码可以成功从指定目录下读取properties配置文件的key和value值,并按照相关业务做相关处理。

欢迎关注微博:http://weibo.com/cxais