标签:extern class getc main final java tom nal cep
package com.starcor.utils; import lombok.extern.slf4j.Slf4j; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * @author dhm * @desc properties文件读取工具类 * @date 2017/11/21 */ @Slf4j public class PropertyUtil { private static Properties props; static { loadProps(); } synchronized static private void loadProps() { log.info("开始加载encrypt.properties文件内容......."); props = new Properties(); InputStream in = null; try { // in = PropertyUtil.class.getClassLoader().getResourceAsStream("encrypt.properties"); in = PropertyUtil.class.getResourceAsStream("/encrypt.properties"); props.load(in); } catch (FileNotFoundException e) { log.error("encrypt.properties文件未找到"); } catch (IOException e) { log.error("出现IOException"); } finally { try { if (null != in) { in.close(); } } catch (IOException e) { log.error("encrypt.properties文件流关闭出现异常"); } } log.info("加载encrypt.properties文件内容完成..........."); } public static String getProperty(String key) { if (null == props) { loadProps(); } return props.getProperty(key); } public static void main(String[] args) { System.out.println(getProperty("name")); } }
标签:extern class getc main final java tom nal cep
原文地址:http://www.cnblogs.com/duanhm234/p/7903416.html