[java]PropertiesUtils操作属性文件

public class PropertiesUtils {

    private static Properties properties = null;

    static {
        if(null == properties){
            properties = new Properties();
            InputStreamReader reader = null;
            try{
                reader = new InputStreamReader(PropertiesUtils.class.getClassLoader().getResourceAsStream("resources.properties"),"utf-8");
                properties.load(reader);
                reader.close();
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                if(reader != null){
                    reader = null;
                }
            }
        }
    }

    private PropertiesUtils(){}

    public static String getString(String key){
        return properties.getProperty(key);
    }

}
发布了170 篇原创文章 · 获赞 30 · 访问量 61万+

猜你喜欢

转载自blog.csdn.net/u010989191/article/details/53436716