zoukankan      html  css  js  c++  java
  • 获取配置文件工具类


    package main.java.sinosoft.utils; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Properties; import org.apache.http.impl.io.SocketOutputBuffer; import org.apache.log4j.Logger; /** * 获取配置文件(读取和jar包同级目录的config.properties的配置文件) * * @author yqzhilan * */ public class PropertyUtils { protected static Logger logger = Logger.getLogger(PropertyUtils.class); //保存系统文件。 private static String sysFile = "config.properties"; private static Properties Sysproperties ; static { Sysproperties = PropertyUtils.getProperties(sysFile); } /** * 获取指定路径下的配置文件信息 * * @param configPath * @return */ public static Properties getProperties(String configPath) { Properties pros = new Properties(); try { ClassLoader cl = ClassLoader.getSystemClassLoader(); ClassLoader.getSystemClassLoader().getResource(sysFile); pros.load(new InputStreamReader(cl.getResourceAsStream(sysFile), "UTF-8")); } catch (IOException e) { e.printStackTrace(); } return pros; } public static String getSysConfigSet(String key){ return Sysproperties.getProperty(key); } }

      获取类路径下的配置文件 

    public class PropertyUitls {
        protected static Logger logger = Logger.getLogger(PropertyUitls.class);
         //保存系统文件。
         private static String sysFile = "config.properties";
         private static Properties Sysproperties ;
         static {
             Sysproperties = PropertyUitls.getProperties(sysFile);
         }
        
        /**
         * 获取指定路径下的配置文件信息
         * 
         * @param configPath
         * @return
         */
        public static Properties getProperties(String configPath) {
            Properties pros = new Properties();
            try {
                ClassLoader cl = PropertyUitls.class.getClassLoader();
                pros.load(new InputStreamReader(cl.getResourceAsStream(configPath), "UTF-8"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return pros;
        }
        
        public static String getSysConfigSet(String key){
            return Sysproperties.getProperty(key);
        }
        
     
    }
  • 相关阅读:
    常用的 JavaScript 简写方法
    user-select详解
    惊人的CSS和JavaScript动画logos例子
    debounce与throttle区别
    Vue.js中data,props和computed数据
    字体图标出现乱码的兼容方案
    ios调用Html内JS alert 不能点击关闭为甚?
    统一诊断服务 (Unified diagnostic services , UDS) (二)
    统一诊断服务 (Unified diagnostic services , UDS) (一)
    CAN总线同步
  • 原文地址:https://www.cnblogs.com/xiaofuzi123456/p/11249551.html
Copyright © 2011-2022 走看看