解析类路径下properties文件

xiaoxiao2021-02-28  104

package com.jointsky.automonitor.alarmnotice.noticemanager.utils; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; /** * 加载配置文件工具类 * 动态加载 * @author Simon * */ public class ConfigFileLoadUtil { /** * 文件名称 */ private final static String FILE_NAME = "cfg.properties"; /** * 根据key获取value * @param key * @return */ public static String getValueByKey(String key){ String value = null; try { Properties p = new Properties(); p.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(FILE_NAME)); value = (String) p.get(key); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return value; } }
转载请注明原文地址: https://www.6miu.com/read-19087.html

最新回复(0)