java读取属性配置文件工具类

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
 * 
 * 类: ProUtil <br>
 * 描述: 属性配置文件读取类 <br>
 * 作者: poseidon<br>
 * 版本: 1.0<br>
 * 时间: 2015-7-17 上午09:20:17
 */
public class ProUtil {
    /* 私有构造方法,防止被实例化 */
    private ProUtil (){};   
    public static Properties  propertie = null;
    static {
         propertie = new Properties();
        InputStream inputStream = ProUtil.class.getResourceAsStream("/config.properties");
        try {
            propertie.load(inputStream);
            inputStream.close();
        } catch (IOException e) {
        }
    }
    
    public static void main(String[] args) {
        System.out.println("--->"+ProUtil.propertie.get("username"));  //username
    }
}
原文地址:https://www.cnblogs.com/likeju/p/4676006.html