断弯刀

导航

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"));
    }
}

 

posted on 2018-10-18 16:24  断弯刀  阅读(565)  评论(0编辑  收藏  举报