import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
import java.text.MessageFormat;
public class PlaceHolderMsg {
public static void main(String args[])
{
//定义一个Locale变量
Locale currentLocale = null;
//如果运行程序制定了两个参数
if(args.length ==2)
{
//使用运行程序的两个参数构造Locale实例
currentLocale = new Locale(args[0],args[1]);
}
else
{
//否则直接使用系统默认的Locale
currentLocale = Locale.getDefault();
}
//根据Locale加载语言资源
ResourceBundle bundle = ResourceBundle.getBundle("MyResource", currentLocale);
//取得已加载的语言资源文件中msg对应消息
String msg = bundle.getString("msg");
//使用MessageFormat为带占位符的字符串传入参数
System.out.println(MessageFormat.format(msg, "yeeku",new Date()));
}
}
-----------------------------------------------------------------------------------
currentLocale = new Locale(args[0],args[1])是什么意思,;
这里好像就用到currentLocale = Locale.getDefault();
其他我都清楚
import java.util.Locale;
import java.util.ResourceBundle;
import java.text.MessageFormat;
public class PlaceHolderMsg {
public static void main(String args[])
{
//定义一个Locale变量
Locale currentLocale = null;
//如果运行程序制定了两个参数
if(args.length ==2)
{
//使用运行程序的两个参数构造Locale实例
currentLocale = new Locale(args[0],args[1]);
}
else
{
//否则直接使用系统默认的Locale
currentLocale = Locale.getDefault();
}
//根据Locale加载语言资源
ResourceBundle bundle = ResourceBundle.getBundle("MyResource", currentLocale);
//取得已加载的语言资源文件中msg对应消息
String msg = bundle.getString("msg");
//使用MessageFormat为带占位符的字符串传入参数
System.out.println(MessageFormat.format(msg, "yeeku",new Date()));
}
}
-----------------------------------------------------------------------------------
currentLocale = new Locale(args[0],args[1])是什么意思,;
这里好像就用到currentLocale = Locale.getDefault();
其他我都清楚
解决方案 »
- Hibernate+jotm+jta+sql server+Tomcat事务不提交问题
- WEBLOGIC8和APACHE2集群配置的小问题
- 浮点型小数点后面怎么取两位???
- 在仅实现到 Servlet 2.3/JSP 1.2 的容器中用 Struts 2 会有什么问题?
- 关于smack jabber客户端文件传输的问题
- Tapestry的Submit组件问题
- 无聊写个小东西玩一下,初学java的一定用的上
- 请教:Web服务器与(Java)应用服务器概念上的差别?谢谢
- jdbc小问题 请大家帮帮忙!!!
- 关于Socket的问题:
- java读取xml
- socket,容器(tomcat/jboss)和jms通讯方式的不同?
这里好像就用到currentLocale = Locale.getDefault(); 你应该先看程序判断:
1.if(args.length ==2)
参数数组长度为2 则执行 currentLocale = new Locale(args[0],args[1])
可能是设定Local,比如你的浏览器默认的的Local是中文“ZH” ,你要读取英文多语言就要手工设置Locale.
currentLocale = new Locale(args[0],args[1]) 就是这个作用
这个构造参数传什么,你可以看API。2.currentLocale = Locale.getDefault(); 获取默认Local,是浏览器来决定的
点开 工具-Internet选项---常规---语言-- 默认Local来至这里的设置。你将英文设置为默认,那么后台获取的就是英文的