I have a resource file (.properties file) which is having thai characters.
When I read that file using the below code it is showing junk characters like "?"
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)
{
}
}
}
And properties file (rd_en_US.properties) is like below
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
Please suggest how to proceed with this.
Thanks in advance, Sandy
If encoding of your file is corrent then you must note that
System.out
will not be able to print the UTF-8 characters with default console settings. Make sure the console you use to display the output is also encoded in UTF-8.In Eclipse for example, you need to go to Run Configuration > Common to do this.