/**
* 解析cfg文件
*
* @param cfgFile
* @return
*/
public Map<String, Object> readCfg(FileInputStream cfgFile) {
Properties prop = new Properties();
Map<String, Object> map = new HashMap<String, Object>();
try {
// 读取cfg属性文件
InputStream in = new BufferedInputStream(cfgFile);
prop.load(new InputStreamReader(in, "GBK")); /// 加载属性列表
Iterator<String> it = prop.stringPropertyNames().iterator();
while (it.hasNext()) {
String key = it.next();
map.put(key, prop.getProperty(key).replaceAll("\"", "").replaceAll(";", ""));
}
in.close();
} catch (Exception e) {
System.out.println(e);
}
return map;
}
解析cfg文件
最新推荐文章于 2024-10-22 12:27:03 发布
本文介绍了一种使用Java读取和解析CFG配置文件的方法,通过Properties类加载文件,并将数据转换为Map格式,便于后续处理。文章详细展示了代码实现过程及异常处理。
1725

被折叠的 条评论
为什么被折叠?



