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 ���¢��
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
):
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)Windows -> Preferences -> General -> Appearence -> Debug -> Console Font
(select Arial, Calibri etc)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:
ฝ่ายขาย