初始化properties

package com.letech.common;

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


public class Constants  {
    protected static Properties    pro    = new Properties();

    static {
        //初始化
        try{
           init("icms.properties");
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public final static String USERNAME = getProperty("userName","");
    protected static void init(String propertyFileName) {
        try {
            pro.load(new IConstants().getClass().getResourceAsStream("/wu.properties"));
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected static String getProperty(String key, String defaultValue) {

        return pro.getProperty(key, defaultValue);
    }    
    
}

 以下是properties

userName=wu

 

posted @ 2020-05-07 16:39  愚蠢的程序员  阅读(841)  评论(0编辑  收藏  举报