1
package com.commons.dormant.resources;
import java.util.Locale;
import java.util.ResourceBundle;
/**
* Commons-Resources没有提供已经发布的jar包,所以没有相关的实例,
* 本例是java自带的和Resources功能相似的例子。主要是实现国际化
* @author chaigw
*
*/
public class TestResourceBundle {
public static void main(String[] args) {
Locale locale1 = new Locale("zh", "CN");
ResourceBundle resb1 = ResourceBundle.getBundle("myres", locale1);
System.out.println(resb1.getString("aaa"));
ResourceBundle resb2 = ResourceBundle.getBundle("myres", Locale.getDefault());
System.out.println(resb2.getString("aaa"));
// 生成一个美国的英语的locale对象。其它详见上面的说明。
Locale locale3 = new Locale("en", "US");
ResourceBundle resb3 = ResourceBundle.getBundle("myres", locale3);
System.out.println(resb3.getString("aaa"));
}
}
2 根目录下两个属性文件xxx_zh_CN.properties/xxx_en_US.properties
aaa=\u597d
bbb=\u591a\u8c22
aaa=good
bbb=thanks
2
zh_CN
/D:/workspace/j2ee/mycommon/bin/com/commons/dormant/resources/myres.properties
好
好
好