读取Properties配置文件的方法,经常忘记,记录下来备忘一下:
package utils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertyConfig {
    private static Properties config;
    static {
        config = new Properties();
        InputStream in = ClassLoader.getSystemResourceAsStream("storm.properties");  //storm.properties 存于 classpath目录下
        try {
            config.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static String getProperty(String key){
        return config.getProperty(key);
    }
    public static void main(String[] args) {
        System.out.println(PropertyConfig.getProperty("key"));
    }
}
原文:http://www.cnblogs.com/liuyunAlex/p/5207900.html