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);
        }
        
     
    }
  • 相关阅读:
    一组网页边栏过渡动画,创意无限!【附源码下载】
    sql查询比较两表不同数据与相同数据
    Sql中的并(UNION)、交(INTERSECT)、差(minus)、除去(EXCEPT)详解
    防盗链基本原理(web安全测试实例二)
    篡改请求数据 或响应数据(web安全测试 实例三)
    【转】思维导图编写测试用例的两种格式
    【转】流媒体与直播技术
    Jmeter接口测试 不同的content-type传入参数方式(一)
    md5算法的java实现
    sql server 2008导出数据至Excel或者wps
  • 原文地址:https://www.cnblogs.com/xiaofuzi123456/p/11249551.html
Copyright © 2011-2022 走看看