Java:在控制台中,泰语文本打印为某些奇怪的字符 [英] Java : In console Thai text is printing as some strange character
本文介绍了Java:在控制台中,泰语文本打印为某些奇怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在控制台中打印泰语字符时,它显示了一些奇怪的字符.
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 ���¢��
推荐答案
假设您在Windows中使用eclipse,以在控制台中启用UTF-8(假设您的IDE能够使用UTF-8编码Windows -> Preferences -> General -> Workspace -> Test File Encoding = UTF-8
) :
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
,选择JRE并进行编辑.将-Dfile.encoding=UTF-8
添加到默认VM参数(或者,您可以编辑eclipse.ini并添加此参数,但对我不起作用)
- 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)
- 选择支持UTF-8的控制台字体:
Windows -> Preferences -> General -> Appearence -> Debug -> Console Font
(选择Arial,Calibri等)
- Select a UTF-8 supporting console font:
Windows -> Preferences -> General -> Appearence -> Debug -> Console Font
(select Arial, Calibri etc)
- 以UTF-8编码形式从您的方法中删除"TIS-620"显式编码
代码:
public static void main(String[] args) throws Exception {
byte[] bytes = "ฝ่ายขาย".getBytes();
String str = new String(bytes);
System.out.println(str);
}
正如注释中所指出的,这是简单的String print
Which is, as pointed out in the comments, simple String print
System.out.println("ฝ่ายขาย");
输出:
ฝ่ายขาย
ฝ่ายขาย
这篇关于Java:在控制台中,泰语文本打印为某些奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文