zoukankan      html  css  js  c++  java
  • 读取配置类

    package com.tl.spider.utils;
    
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.util.Properties;
    
    /**
     * @ClassName ReadConfigUtil
     * @Description 配置文件的读取类
     * @Author Administrator
     * @Date 2019/5/19 16:24
     * @Version 1.0
     **/
    public class ReadConfigUtil {
        private String configPath;
        private Properties property;
    
        /**
         * 
         * @param configPath
         * @throws Exception
         */
        public ReadConfigUtil(String configPath) throws Exception {
            this.configPath = configPath;
            
            InputStream is = ReadConfigUtil.class.getClassLoader().getResourceAsStream(this.configPath);
            Reader reader = new InputStreamReader(is, StaticValue.ENCODING_DEFAULT);
            property = new Properties();
            property.load(reader);
            reader.close();
        }
    
        /**
         * 读取具体的某项配置
         * @param key
         * @return
         */
        public String getValue(String key) {
            return property.getProperty(key);
        }
    
        public static void main(String[] args) throws Exception {
            String configPath = "spider.properties";
            ReadConfigUtil readConfigUtil = new ReadConfigUtil(configPath);
            System.out.println(readConfigUtil.getValue("database_url"));
            System.out.println(readConfigUtil.getValue("database_userame"));
            System.out.println(readConfigUtil.getValue("database_password"));
            
        }
    }
    

      

  • 相关阅读:
    Http请求头与响应头
    获取ip位置方法
    简单的Http Server实现
    HTTP
    long、int与byte数组之间的相互转换
    GlusterFS简单配置
    创建线程池
    网络编程socket
    面向对象-进阶篇
    面向对象-初级篇
  • 原文地址:https://www.cnblogs.com/wylwyl/p/10889757.html
Copyright © 2011-2022 走看看