| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package com.kingdee.eas.custom.beisen.utils;
- import com.google.common.collect.Maps;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.log4j.Logger;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.Map;
- import java.util.Properties;
- import java.util.Set;
- /**
- * 获取配置文件参数值
- * description: BeisenParamByProperties <br>
- * date: 2025/7/7 16:03 <br>
- * author: lhbj <br>
- * version: 1.0 <br>
- */
- public class BeisenParamByPropertiesUtil {
- private static Logger logger =Logger.getLogger(BeisenParamByPropertiesUtil.class);
- private Properties propt = new Properties();//共用参数
- /**
- * filePath地址从server开始,例:/server/properties/beisen/beisenConfig.properties
- * @param filePath
- */
- public BeisenParamByPropertiesUtil(String filePath) throws IOException {
- this.initConfig(System.getProperty("EAS_HOME") + filePath);
- }
- public BeisenParamByPropertiesUtil() throws IOException {
- }
- public BeisenParamByPropertiesUtil initConfig(String filePath) throws IOException {
- try {
- if(StringUtils.isBlank(filePath)){
- throw new IOException("filePath参数为空");
- }
- this.propt.load(new FileInputStream(filePath));
- return this;
- }catch (IOException e){
- e.printStackTrace();
- logger.error("未找到"+filePath+"配置文件。");
- throw e;
- }
- }
- public Map<String,String> getConfig() {
- Map<String,String> map = Maps.newHashMap();
- Set<Map.Entry<Object, Object>> set = this.propt.entrySet();
- for(Map.Entry<Object, Object> entry : set){
- map.put((String)entry.getKey(),(String)entry.getValue());
- }
- return map;
- }
- }
|