3.2.2.1 类:PropertyUtil

该类是一个工具类, 可以读取配置文件: kafka-hbase.properties中属性的值.

通过方法getProperty() 可以获取你需要的属性的值

package com.atguigu.dataconsumer.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyUtil {

    public static Properties properties;

    static {
        InputStream is = ClassLoader.getSystemResourceAsStream("kafka-hbase.properties");
        properties = new Properties();
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 根据指定的属性名返回对应的属性值
     *
     * @param propertyName
     * @return
     */
    public static String getProperty(String propertyName) {
        if (properties != null) {
            return properties.getProperty(propertyName);
        }
        return null;
    }
}
Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2019-01-14 05:27:28

results matching ""

    No results matching ""