0

I have a problem with reading the Thai language from code java below:

if(objArr[22].toString().equals("MISS")){
    LOGGER.info("This is นางสาว." + objArr[6].toString());
    byte[] bytes = "นางสาว.".getBytes();
    String title = new String(bytes);
    classAttendanceDetailDTO.setAgentName(title + objArr[6].toString());
} else if(objArr[22].toString().equals("MR")){
    LOGGER.info("This is นาย." + objArr[6].toString());
    byte[] bytes = "นาย.".getBytes();
    String title = new String(bytes);
    classAttendanceDetailDTO.setAgentName(title + objArr[6].toString());
} else if(objArr[22].toString().equals("MRS")){
    LOGGER.info("This is นาง." + objArr[6].toString());
    byte[] bytes = "นาง.".getBytes();
    String title = new String(bytes);
    classAttendanceDetailDTO.setAgentName(title + objArr[6].toString());
} else{
    LOGGER.info("Not have title");
    classAttendanceDetailDTO.setAgentName("-" + objArr[6].toString());
    }

When I print text in the console log with Thai language, the log will show strange language ???? like below : enter image description here

Anyone can help me config to read the Thai language in this code? I also set UTF-8 for default encoding but it is inefficient. enter image description here

enter image description here

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
Einz
  • 37
  • 5
  • The encoding you used is wrong. You need to use UTF-8 mode. Go to `Window > Preferences > General > Content Types`, set UTF-8 as the default encoding for all content types. https://stackoverflow.com/q/9180981/8242447 can help you. – Ṃųỻịgǻňạcểơửṩ Jan 03 '20 at 03:58
  • 1
    I used UTF-8 for all content types as you said with this blog: https://stijndewitt.com/2010/05/05/unicode-utf-8-in-eclipse-java/ but it is inefficient – Einz Jan 03 '20 at 04:09
  • Did that solve your question? – Ṃųỻịgǻňạcểơửṩ Jan 03 '20 at 04:10
  • 1
    Setting the encoding for the `Text` content type does not set it for all the subtypes, like Java source files. And is there a reason you're converting the text to bytes and then back into a String? That potentially makes it subject to a different character set conversion when executing. – nitind Jan 03 '20 at 04:36
  • @nitind : I try coding `String s = "นางสาว"; System.out.println(s);` but it also print ??? in log – Einz Jan 03 '20 at 04:46
  • This problem can be caused by complier javac, anyone know how to set javac-encoding UTF-8 ? – Einz Jan 03 '20 at 07:35
  • 4
    Check that the font used by the console can actually display these characters (Preferences - General > Appearance > Colors and Fonts > Debug > Console font) – greg-449 Jan 03 '20 at 07:40
  • Eclipse doesn't use `javac` unless you are using an external build system like Maven, Gradle, or Ant. – nitind Jan 03 '20 at 09:17

0 Answers0