• 设置配置文件


    package com.manage;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    
    public class ProjectUtil {
        /**
         * 使用log4j配置打印日志
         */
        static final Logger logger = Logger.getLogger(UseZookeeperManageOffset.class);
        /**
         * 加载配置的log4j.properties,默认读取的路径在src下,如果将log4j.properties放在别的路径中要手动加载
         */
        public static void LoadLogConfig() {
            PropertyConfigurator.configure("d:/eclipse4.7WS/SparkStreaming_Kafka_Manage/resource/log4j.properties"); 
        }
        
        /**
         * 加载配置文件
         * 需要将放config.properties的目录设置成资源目录
         * @return
         */
        public static Properties loadProperties() {
    
            Properties props = new Properties();
            InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
            if(null != inputStream) {
                try {
                    props.load(inputStream);
                } catch (IOException e) {
                    logger.error(String.format("Config.properties file not found in the classpath"));
                }
            }
            return props;
    
        }
        
        public static void main(String[] args) {
            Properties props = loadProperties();
            String value = props.getProperty("zookeeper");
            System.out.println(value);
        }
    }

    。。

  • 相关阅读:
    Java基本数据类型的包装类
    Java数据类型基础
    Xscan安装
    Notepad++配置HexEditor插件
    [WP]XCTF-re2-cpp-is-awesome
    [WP]XCTF-tt3441810
    [WP]XCTF-re1-100
    [WP]XCTF-Mysterious
    [WP]xctf-parallel-comparator-200
    [WP]XCTF-elrond32
  • 原文地址:https://www.cnblogs.com/guoyu1/p/16352795.html
Copyright © 2020-2023  润新知