µ±Ç°Î»Ö㺠´úÂëÃÔ >> ×ÛºÏ >> ResourceBundle ²Ù×÷propertiesÎļþºÍ¹ú¼Ê»¯
  Ïêϸ½â¾ö·½°¸

ResourceBundle ²Ù×÷propertiesÎļþºÍ¹ú¼Ê»¯

Èȶȣº93   ·¢²¼Ê±¼ä£º2023-12-14 03:13:10.0

ResourceBundle   

JavaÓïÑÔÌṩÁËResourceBundleÀàÀ´¶ÔpropertiesÀàÐ͵Ä×ÊÔ´Îļþ¼ÓÒÔ´¦Àí¡£

±¾ÎĶÔResourceBundleÀà×öÒ»¸ö½â˵¡£

¿ªÊ¼Ö®Ç°£¬ÎÒÃÇÏȽâÊÍÒ»ÏÂʲôÊÇpropertiesÀàÐ͵Ä×ÊÔ´Îļþ¡£

ÔÚJavaÓïÑÔÖУ¬Ê¹ÓÃÒ»ÖÖÒÔ.propertiesΪÀ©Õ¹ÃûµÄÎı¾Îļþ×÷Ϊ×ÊÔ´Îļþ£¬¸ÃÀàÐ͵ÄÎļþµÄÄÚÈݸñʽΪÀàËÆ£º

#×¢ÊÍÓï¾ä

some_key=some_value

ÐÎʽ¡£ÒÔ#¿ªÍ·µÄÐÐ×÷ΪעÊÍÐУ¬ResourceBundleÀà´¦Àíʱ»á¼ÓÒÔºöÂÔ£»ÆäÓàµÄÐпÉÒÔÒÔ keyÃû=valueÖµ µÄÐÎʽ¼ÓÒÔ¼ÇÊö¡£

JavaµÄResourceBundleÀà¿ÉÒÔ¶ÔÕâÖÖÐÎʽµÄÎļþ¼ÓÒÔ´¦Àí¡£

1£©×ÊÔ´Îļþ

ApplicationResources_zh_CN.properties               //ººÓï

ApplicationResources_en_ES.properties               //Ó¢Óï

ApplicationResources_ja_JP.properties                  //ÈÕÓï

×ÊÔ´ÎļþÓÐÒ»ÌõÕâÑùµÄ¼Ç¼£º

xihu                        Î÷ºþ                            west lake            ¤³¤ó¤Ë¤Á¤Ï        

2£©java´úÂë

String resourceFile = "test3\\ApplicationResources";   
//  Locale locale_cn = new Locale("zh","CN");
  Locale locale_es = new Locale("en","ES");
//  Locale locale_ja = new Locale("ja","JP");
//  ResourceBundle resource_cn = ResourceBundle.getBundle(resourceFile,locale_cn);                   
  ResourceBundle resource_es = ResourceBundle.getBundle(resourceFile,locale_es);
//  ResourceBundle resource_ja = ResourceBundle.getBundle(resourceFile,locale_ja);
//  System.out.println(resource_cn.getString("xihu"));
  System.out.println(resource_es.getString("xihu"));  
//  System.out.println(resource_ja.getString("xihu"));

³ÌÐòÖ´ÐÐÊä³öµÄ½á¹û·Ö±ðΪ£º

Î÷ºþ

west lake

¤³¤ó¤Ë¤Á¤Ï

 

ÒÔÉϾÍÊÇͨ¹ýResourceBundleʵÏÖ¹ú¼Ê»¯ÏÔʾ¡£

Õª×Ô:http://blog.163.com/daixihu_2008/blog/static/941948662009475513412/

  Ïà¹Ø½â¾ö·½°¸