笔记读取properties文件
Posted 我的bug
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了笔记读取properties文件相关的知识,希望对你有一定的参考价值。
package com.bshinfo.el.userInfo.util; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; public class SystemConfigUtil { private static SystemConfigUtil systemConfigUtil = null; private static Map<String, String> proMap = new HashMap<String, String>(); private SystemConfigUtil() { Properties pro = new Properties(); try { pro.load(new InputStreamReader(SystemConfigUtil.class.getClassLoader().getResourceAsStream("printgz.properties"), "UTF-8"));//默认根目录下 Enumeration e = pro.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = (String) pro.get(key); proMap.put(key, value); } } catch (IOException e) { e.printStackTrace(); } } public static SystemConfigUtil getInstance() { if (systemConfigUtil == null) { systemConfigUtil = new SystemConfigUtil(); } return null; } public static Map<String, String> getProMap() { return proMap; } public static void main(String[] args) { // 写一个main方法,来验证一下 SystemConfigUtil systemConfigUtil = SystemConfigUtil.getInstance(); SystemConfigUtil systemConfigUtil2 = SystemConfigUtil.getInstance(); System.out.println(systemConfigUtil == systemConfigUtil2); Map m1 = systemConfigUtil.getProMap(); Map m2 = systemConfigUtil2.getProMap(); System.out.println(m1 == m2); System.out.println(m1.get("test")); System.out.println(m1.get("燃油值班员")); } }
以上是关于笔记读取properties文件的主要内容,如果未能解决你的问题,请参考以下文章
[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段