Java:在控制台泰语文本打印为一些奇怪的字符

Arv*_*ind 3 java eclipse utf-8 character-encoding thai

当我在控制台中打印泰国字符时,它显示出一些奇怪的特征.

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

它打印 ¢

Pop*_*ibo 5

假设您在Windows中使用eclipse,在控制台中启用UTF-8(假设您的IDE能够使用UTF-8编码Windows -> Preferences -> General -> Workspace -> Test File Encoding = UTF-8):

  1. 转到Windows -> Preferences -> Java -> Installed JREs,选择JRE和编辑.添加-Dfile.encoding=UTF-8到默认VM参数(或者您可以编辑您的eclipse.ini并添加此参数,但它对我不起作用)

在此输入图像描述

  1. 选择支持UTF-8的控制台字体:( Windows -> Preferences -> General -> Appearence -> Debug -> Console Font选择Arial,Calibri等)

在此输入图像描述

  1. 根据您的方法从UTF-8编码形式中删除"TIS-620"显式编码

码:

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

        String str = new String(bytes);
        System.out.println(str);
    }
Run Code Online (Sandbox Code Playgroud)

正如评论中指出的那样,简单的字符串打印

System.out.println("???????");
Run Code Online (Sandbox Code Playgroud)

输出:

ฝ่ายขาย