1>resource.java文件内容:
/* * 资源文件的使用 * //1>设置地区 * Locale zhLoc = new Locale("zh", "CN"); * //2>找到资源属性文件 * ResourceBundle rbzh = ResourceBundle.getBundle("com.resource/Message",zhLoc); * //3>通过键值读取内容 * rbzh.getString("info"); */ package com.resource; import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; public class resource { public static void main(String args[]){ /* //找到资源文件 ResourceBundle rb = ResourceBundle.getBundle("com.resource/en"); //从资源文件中取得内容 String country = rb.getString("country"); System.out.println(country);*/ Locale zhLoc = new Locale("zh", "CN"); Locale enLoc = new Locale("en", "US"); Locale frLoc = new Locale("fr", "FR"); //找到中文的属性文件 ResourceBundle rbzh = ResourceBundle.getBundle("com.resource/Message",zhLoc); //找到英文的属性文件 ResourceBundle rben = ResourceBundle.getBundle("com.resource/Message",enLoc); //找到法语的属性文件 ResourceBundle rbfr = ResourceBundle.getBundle("com.resource/Message",frLoc); String strCh=MessageFormat.format(rbzh.getString("info"),"肖红阳"); String strEn=MessageFormat.format(rben.getString("info"),"Xiaohongyang"); String strFr=MessageFormat.format(rbfr.getString("info"),"Xhy"); System.out.println("中文:"+strCh); System.out.println("英文:"+strEn); System.out.println("法语:"+strFr); } }
2>Message_en_US.properties文件内容
info = Hello {0};
3>Message_fr_FR.properties文件内容
info = Bonjour {0};
4>Message_zh_CN.properties文件内容
info = \u4F60\u597D {0};