Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I am printing thai character in console it is showing some strange character.

public static void main(String[] args) throws Exception{
        byte[] bytes = "???????".getBytes("TIS-620");
        String str =  new  String(bytes);
        System.out.println(str);
}

It is printing ???¢??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
866 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming you're using eclipse in Windows, to enable UTF-8 in console (given that your IDE is able to use UTF-8 encoding Windows -> Preferences -> General -> Workspace -> Test File Encoding = UTF-8 ):

  1. Go to Windows -> Preferences -> Java -> Installed JREs, select the JRE and Edit. Add -Dfile.encoding=UTF-8 to Default VM arguments (alternatively you can edit your eclipse.ini and add this argument but it doesn't work for me)

enter image description here

  1. Select a UTF-8 supporting console font: Windows -> Preferences -> General -> Appearence -> Debug -> Console Font (select Arial, Calibri etc)

enter image description here

  1. Remove "TIS-620" explicit encoding from your method as you need it in UTF-8 encoded form

Code:

public static void main(String[] args) throws Exception {
        byte[] bytes = "???????".getBytes();

        String str = new String(bytes);
        System.out.println(str);
    }

Which is, as pointed out in the comments, simple String print

System.out.println("???????");

Output:

???????


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...