【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-TextPropI18N.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
package com.zf.s8;//创建一个包
import java.util.Locale;//引入类
import java.util.ResourceBundle;
public class TextPropI18N {// 操作使用属性文件实现资源国际化的类
public static final String PROP_FILENAME = "com.zf.s8.resource";
public static final String POEM_KEY = "poem";
public static final String GLOBAL_KEY = "poem.global";
public static final String TEST = "test";
private static String poem;
private static String global;
private static String test;
public static void showI18N() {// 操作属性文件的方法
try {
Locale locale = Locale.ENGLISH;//使用英文
ResourceBundle bundle = ResourceBundle.getBundle(PROP_FILENAME, locale);
poem=bundle.getString(POEM_KEY).trim();//获得键poem对应的值
global=bundle.getString(GLOBAL_KEY).trim();//获得键global对应的值
test=bundle.getString(TEST);//获取只在resource.properties存在的键
System.out.println("poem使用默认值:"+poem);
System.out.println("global使用默认值:"+global);
System.out.println("test使用默认值:"+ test);
locale=Locale.CHINESE;//使用简体中文
bundle = ResourceBundle.getBundle(PROP_FILENAME, locale);
poem=bundle.getString(POEM_KEY).trim();
global=bundle.getString(GLOBAL_KEY).trim();
test=bundle.getString(TEST);
System.out.println("poem使用默认值:"+poem);
System.out.println("global使用默认值:"+global);
System.out.println("test使用默认值:"+ test);
} catch (Exception e) {
System.err.println("不能加载属性文件");
poem="default poem";
global="default global";
test="default test";
}
}
public static void main(String[] args) {//java程序主入口处
TextPropI18N text = new TextPropI18N();//实例化对象
text.showI18N();//调用方法显示信息
}
}
上一篇:
TextPropertiesSendMail.java
下一篇:
让我掉下眼泪的