static ResourceBundle res = ResourceBundle.getBundle("你的资源文件放的位置");
若你的资源文件名xxxx.properties,xxxx_zh_CN.properties(各国语言的properties文件).......在com.xxj下面,就可以写为“com.xxj.xxxx”.

解决方案 »

  1.   

    举例:
    xxxx.properties里面有一行
    routingChange_ToolTipText=Show cargo Information.那么在java文件里面就可以用下面方法取:
    res.getString("routingChange_ToolTipText");
      

  2.   

    查找properties文件是根据你自己机器的配置的,ResourceBundle.getBundle("你的资源文件放的位置")里面就写“com.xxj.xxxx”就可以了。
    如果你机器的编码为中文,就会自动读“xxxx_zh_CN.properties”文件,如果不是,而且没有该国语言的properties文件,那么默认最后退为读取xxxx.properties。呵呵,先进吧!
      

  3.   

    to : xuxijian2003(xxj)
    你看看我写的程序,为什么出现乱码?主程序为:
    import java.util.ResourceBundle;
    import java.util.Locale;public class MyRB{
       public static void main(String[] args) throws Exception{
         String[] language = new String[2];
         String[] country = new String[2];
         language[0] = "en";
         language[1] = "zh";
         country[0] = "US";
         country[1] = "CH";
         Locale currentLocale1 = new Locale(language[0], country[0]);
         Locale currentLocale2 = new Locale(language[1], country[1]);
         ResourceBundle messages1 = ResourceBundle.getBundle("test", currentLocale1);
         ResourceBundle messages2 = ResourceBundle.getBundle("test", currentLocale2);
         System.out.println(messages1.getString("Chinese"));
         System.out.println(messages1.getString("American"));
         System.out.println(messages1.getString("Japanese"));
         System.out.println(messages2.getString("Chinese"));
         System.out.println(messages2.getString("American"));
         System.out.println(messages2.getString("Japanese"));
       }
    }两个资源文件为:
    test_en_US.propertiesChinese = Chinese
    American = American
    Japanese = Japanesetest_zh_CH.properties
    Chinese = 中国人
    American = 美国人
    Japanese = 日本人运行结果为:
    Chinese
    American
    Japanese
    ???ú??
    ???ú??
    ??±???
      

  4.   

    哈哈,当然是乱码了。是这样的,你必须先要转化为assicc码:
    结果properties里面应该写成这样:
    Chinese = \u4e2d\u56fd\u4eba
    American = \u7f8e\u56fd\u4eba
    Japanese = \u65e5\u672c\u4eba
    流程这样:
    找到你的jdk(jbuilder下就有),在目录bin下执行
    native2ascii.exe  -encoding GBK xxxx.properties xxxx_zh_CN.properties
    其中xxxx.properties 里先写中文。xxxx_zh_CN.properties是生成的文件,如果有先删除。
    然后你把你的xxxx.properties 里面的东西改为你的英文好了。
    知道了?
    如果这样还不行,xxxx_zh_CN.properties改为xxxx_zh.properties试一下,应为xxxx_zh_CN.properties找不到,接下来会找xxxx_zh.properties,xxxx_zh.properties再没有就找xxxx.properties 。
    可以当经典收藏了,呵呵
      

  5.   

    具体可以参考JAVA_HOME\demo\jfc下面的Notepad例子
      

  6.   

    to : xuxijian2003(xxj)
    谢谢你!这个问题解决了,我还想问你一个问题:利用这个类能实现自动读取相应的properties文件吗?还是需要程序员自己先判断用户的平台支持什么语言,再读取相应的文件?
      

  7.   

    当地语言的获取,Locale l = Locale.getDefault();ResourceBundle bundle = ResourceBundle.getBundle("...............", l);
      

  8.   

    不要自己判断的呀,如果找不到你的机器平台语言,那么会自动找XXXX.properties文件的。她内部的寻找方法是这样的,以中文为例,有三个这样的文件XXXX.properties,XXXX_zh.properties,XXXX_zh_CN.properties,假如你的机器是中国区域且是中文,那么会自动用XXXX_zh_CN.prop,如果你的机器是中文但不在中国区域,那么自动识别XXXX_zh.properties,如果都不是,只有识别XXXX.properties了。XXXX.properties是最后一道防线。