ResourceBundle

1,ResourceBundle是读取配置文件内容,和读取国际化配置文件内容,可以直接读xxx.properties,也可以读取xxx_zh_CN.properties或xxx_en_US.properties。


2,当直接读取xxx.properties,是通过ResourceBundle.getBundle(配置文件位置),
配置文件位置:当message.properties在src下:/message.properties。
当message.properties在src下的com下的action里:/com/action/message。
其中“/”表示src下
如:private String configFile="/com/action/message";
ResourceBundle resourceBundle=ResourceBundle.getBundle(this.configFile,locale);
String name_=resourceBundle.getString("name");
String password_=resourceBundle.getString("password");


message.properties内容:
name=bbbbbbbb
password=1111111


ResourceBundle通过getBundle来得到对象,然后通过对象的getString(key)来得到value。




3,ResourceBundle也可以读取国际化的配置文件,首先需要创建Locale的对象,这个Locale是配置哪一个国际化
如:private String configFile="/com/action/message";
private String locale_1="en";//或zh
private String locale_2="US";//或CN
Locale locale=new Locale(this.locale_1,this.locale_2);


ResourceBundle resourceBundle=ResourceBundle.getBundle(this.configFile,locale);
String name_=resourceBundle.getString("name");
String password_=resourceBundle.getString("password");
然后读取的是message_en_US.properties这个配置文件。
locale_1值为zh,locale_2值为CN时,读取的是message_zh_CN.properties这个配置文件。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值