繁体   English   中英

无法从java中的.properties资源文件中读取泰文字符

[英]Unable to read thai characters from .properties resource file in java

我有一个具有泰国字符的资源文件(.properties文件)。

当我使用下面的代码读取该文件时,它显示像“?”这样的垃圾字符

package RD1.Common;

import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;

public class LabelManagerRD {

   public static String[] getLabel(String ParamString1)
    {

      String NextEle = "";
      String str2 = ParamString1;
      int i = 1;

      String Final[] = new String[1000];

      ResourceBundle bundle =
              ResourceBundle.getBundle("rd", Locale.US);

      Enumeration<String> enumeration = bundle.getKeys();

      while (enumeration.hasMoreElements()) 
        {
             NextEle = enumeration.nextElement();

             if (NextEle.toLowerCase().contains(str2.toLowerCase()))
             {
                 Final[i] = NextEle+"="+bundle.getString(NextEle);
                 i++;
             }
      }

    return Final;

    }


   public static void main(String[] args)
    {
       try
       {
        String TestValue[] = getLabel("RD.RDRAPCEX");
        for(int i=1;i<=TestValue.length;i++)
        {   
            if (!(TestValue[i].length()==0))
            {
                System.out.println(i+" - "+TestValue[i]);
            }

        }
       }
       catch (Exception e)
       {

       }


    }
}

属性文件(rd_en_US.properties)如下所示

BL_BLNG_GROUP.BL_BLNG_GRP.BLNG_GRP_ID.IP=รสสรืเ เพนีย รก~^PAGE_1~^Y~^N
BL_BLNG_GROUP.BL_BLNG_GRP.LONG_DESC.IP=Long Desc~^PAGE_1~^Y~^N
BL_BLNG_GROUP.BL_BLNG_GRP.SHORT_DESC.IP=Short Desc~^PAGE_1~^Y~^N
BL_BLNG_GROUP.BL_BLNG_GRP.DETAIL_DESC.IP=Explanatory Note~^PAGE_1~^Y~^N

请建议如何继续这样做。

谢谢,桑迪

如果您的文件编码是正确的,那么您必须注意System.out将无法使用默认控制台设置打印UTF-8字符。 确保用于显示输出的控制台也以UTF-8编码。

例如,在Eclipse中,您需要转到Run Configuration> Common来执行此操作。

在此输入图像描述

属性文件通常以ISO 8859-1编码解释。 如果您需要此集合中未包含的其他字符,请使用unicode转义\\uxxxx例如\\uxxxx 还有一些工具可用于将具有不同编码的属性文件转换为此文件(请参阅native2ascii )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM