PropertiesUtil

PropertiesUtil

package com.zjx.util;

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

public class PropertiesUtil {

    /**
     * 通过key获取value
     * @param key
     * @return
     */
    public static String getValue(String key){
        Properties prop=new Properties();
        InputStream in=new PropertiesUtil().getClass().getResourceAsStream("/crawler.properties");
        try {
            prop.load(in);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return prop.getProperty(key);
    }
    
    public static void main(String[] args) {
        System.out.println(PropertiesUtil.getValue("dbUsername"));
    }
}
原文地址:https://www.cnblogs.com/duanwandao/p/9811295.html