62,614
社区成员
发帖
与我相关
我的任务
分享
MyResource_en_US.properties
MyResource_zh_CN.properties
//MyResource_zh_CN.properties
msg=\u4f60\u597d,{0}!\u4eca\u5929\u662f {1}.
//MyResource_en_US.properties
msg=Hello,{0}!Today is {1}.
//Hello.java
import java.text.MessageFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
public class Hello {
static Locale currentLocale=null;
public static void main(String[] args)
{
if(args.length==2)
{
currentLocale=new Locale(args[0],args[1]);
}
else
{
currentLocale=Locale.getDefault();
}
ResourceBundle bundle=ResourceBundle.getBundle("MyResource", currentLocale);
String msg=(String)bundle.getObject("msg");
MessageFormat mf=new MessageFormat("");
mf.setLocale(currentLocale);
mf.applyPattern(msg);
Date now=new Date();
Object[] msgParams={"yeeku",now};
System.out.println(mf.format(msgParams));
}
}