eg:
public class Commons {
//工具类创建常量
public static String EMAIL_ACCOUNT;
public static String EMAIL_PASSWORD;
//静态区域块读取 properties
static{
ResourceBundle resource=ResourceBundle.getBundle("init");
EMAIL_ACCOUNT=resource.getString("email_account").trim();
EMAIL_PASSWORD=resource.getString("email_password").trim();
}
//创建的 properties 配置
email_account=ygc@qq.com
email_password=ygc123456
//在程序里可以通过类+常量名直接调用定义在properties 的配置信息
Commons.EMAIL_ACCOUNT;
Commons.EMAIL_PASSWORD