首页 > 学院 > 开发设计 > 正文

读取properties配置文件代码

2019-11-08 02:33:24
字体:
来源:转载
供稿:网友
public class ConfigUtils {PRivate static final Logger log = Logger.getLogger(ConfigUtils.class);private static final String DEPLOY_CONFIG_PROPERTIES = "deploy-config.properties";private static final String OperaTION_CONFIG_PROPERTIES = "operation-config.properties";private static final Map<String, String> map = new HashMap<String, String>();static {InputStream deployIn = ConfigUtils.class.getClassLoader().getResourceAsStream(ConfigUtils.DEPLOY_CONFIG_PROPERTIES);InputStream operationIn = ConfigUtils.class.getClassLoader().getResourceAsStream(ConfigUtils.OPERATION_CONFIG_PROPERTIES);Properties properties = new Properties();try {properties.load(deployIn);properties.load(operationIn);Set<Entry<Object, Object>> entrys = properties.entrySet();for (Entry<Object, Object> entry : entrys) {map.put(entry.getKey().toString(), entry.getValue().toString());}} catch (IOException e) {log.error("load upload.properties wrong");log.error(e.toString());} finally {try {deployIn.close();operationIn.close();} catch (IOException e) {log.error(e.toString());}}}/*** 依据key获取对应的value* @param key* @return*/public static String getValue(String key) {String value = null;String keyValue = map.get(key);if (StringUtils.isNotBlank(keyValue)) {value = keyValue.trim();}return value;}}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表