java中常量文件的配置与读取:

 package com.floor.shop.user.util;

 import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties; /**
* 课程笔记:http://www.cnblogs.com/newAndHui/category/1153640.html
* 疑问咨询wx:851298348
*/
public class ConfigMapUtil {
private static Map<String, String> map = new HashMap<>(); static {
try {
//读取文件流
InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
//转变为字符流
InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream,"utf-8");
//创建 Properties 对象
Properties properties = new Properties();
// prop.load(new InputStreamReader(in, "utf-8"));
//加载字符流
properties.load(inputStreamReader);
//获取所有key
Enumeration enumeration = properties.propertyNames();
while (enumeration.hasMoreElements()) {
//遍历key
String key = (String) enumeration.nextElement();
//根据key取值
String value = properties.getProperty(key);
//放入map中
map.put(key, value);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getShopWx() {
return map.get("shop.wx");
}
public static String getValueByKey(String key) {
return map.get(key);
} public static Map<String, String> getMap() {
return map;
} public static void setMap(Map<String, String> map) {
ConfigMapUtil.map = map;
} }

3.测试:

最新文章

  1. DOM Element节点类型详解
  2. Thinking in Java——笔记(3)
  3. Python全栈--7模块--random os sys time datetime hashlib pickle json requests xml
  4. iOS NSDate计算时间间隔
  5. JavaScript 之 走马灯
  6. acrobat GetSize 返回 x,y 值单位
  7. android studio 报ambiguous method call
  8. iptables 实现centos内网机器访问外网
  9. shrio初体验(2)Realm
  10. 软工+C(2017第6期) 最近发展区/脚手架
  11. from bs4 import BeautifulSoup 报错
  12. Flask中Mysql数据库的常见操作
  13. vue 工作学习总结
  14. 27、通过visual s&#39;tudio 验证 SOCKET编程:搭建一个TCP服务器
  15. VS2012使用验证控件出现[ASP.NET]WebForms UnobtrusiveValidationMode 需要 &#39;jquery&#39; 的 ScriptResourceMapping。請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)。的解决办法。
  16. TensorFlow queue多线程读取数据
  17. Django之集合函数使用与mysql表的创建特殊字段分析
  18. IDEA 的主题设置
  19. IIS 7.0 SSL 部署指南
  20. 加密算法(对称加密)AES、DES (非对称加密)RSA、DSA

热门文章

  1. Maven2查看源码
  2. XMLHttpRequest详解
  3. mybatis批量插入和批量更新
  4. Codeforces Round #545 (Div. 1)
  5. asp.net 的三种开发模式
  6. Go语言之unsafe包介绍及使用
  7. BZOJ2124 等差子序列(树状数组+哈希)
  8. Code First 重复外键
  9. git报错failed to push some refs to &#39;git@github.com:Markprint/github.git&#39;
  10. 16 利用Zabbix完成windows监控