package com.template.common.utils; import java.io.*; import java.net.URI; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; /** *
Title: PropertiesUtil
*Description: properties资源文件解析工具
* @author fengyong * @date 2018年9月7日 */ public class PropertiesUtil { private static Properties props = null; private static URI uri; private static String fileName = "/application.properties"; private static InputStream in = null; static { try { props = new Properties(); InputStream fis = PropertiesUtil.class.getResourceAsStream(fileName); props.load(fis); uri = PropertiesUtil.class.getResource(fileName).toURI(); } catch (Exception e) { e.printStackTrace(); } } /** * 获取某个属性 */ public static String getProperty(String key) { try { props.load(PropertiesUtil.class.getResourceAsStream(fileName)); } catch (IOException e) { e.printStackTrace(); } return props.getProperty(key); } /** * 获取所有属性,返回一个map,不常用 可以试试props.putAll(t) */ @SuppressWarnings("rawtypes") public static Map