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);
        }
        
     
    }
  • 相关阅读:
    A2-02-15.DML-MySQL RIGHT JOIN
    A2-02-14.DML- MySQL LEFT JOIN
    A2-02-13.DML- MySQL INNER JOIN
    NHibernate N+1问题实例分析和优化
    怎么创建移动页面应用程序
    .NET开发时让人头痛的SESSION超时
    WCF服务编程——数据契约快速入门
    数据模型类对比,用反射做个快乐的程序员
    javascript常见数据集
    provider:命名管道提供程序,error:40
  • 原文地址:https://www.cnblogs.com/xiaofuzi123456/p/11249551.html
Copyright © 2011-2022 走看看