当我在控制台中打印泰语字符时,它显示出一些奇怪的字符。
public static void main(String[] args) throws Exception{
byte[] bytes = "ฝ่ายขาย".getBytes("TIS-620");
String str = new String(bytes);
System.out.println(str);
}
它正在打印������</p>
当我在控制台中打印泰语字符时,它显示出一些奇怪的字符。
public static void main(String[] args) throws Exception{
byte[] bytes = "ฝ่ายขาย".getBytes("TIS-620");
String str = new String(bytes);
System.out.println(str);
}
它正在打印������</p>
假设您在 Windows 中使用 eclipse,以在控制台中启用 UTF-8(假设您的 IDE 能够使用 UTF-8 编码Windows -> Preferences -> General -> Workspace -> Test File Encoding = UTF-8
):
Windows -> Preferences -> Java -> Installed JREs
,选择 JRE 并编辑。添加-Dfile.encoding=UTF-8
到默认 VM 参数(或者您可以编辑 eclipse.ini 并添加此参数,但它对我不起作用)Windows -> Preferences -> General -> Appearence -> Debug -> Console Font
选择 Arial、Calibri 等)代码:
public static void main(String[] args) throws Exception {
byte[] bytes = "ฝ่ายขาย".getBytes();
String str = new String(bytes);
System.out.println(str);
}
正如评论中指出的那样,简单的 String print
System.out.println("ฝ่ายขาย");
输出:
ฝ่ายขาย</p>