如何在 JTextArea 中显示任何非英文字符?我尝试了不同的方法,但没有一个有效。以下代码为任何非英语字符(如日语)打印乱码。在调试模式下,变量 msgUtf8Str 确实正确显示了本地字符。支持的字符集可以很大,示例包括:日语、中文(普通话)、法语、德语等。
String msgUtf8Str = null;
byte[] msgUtf8= message.getBytes(Charset.forName("UTF-8"));
try
{
msgUtf8Str = new String(msgUtf8, "UTF-8");
}
catch(Exception ex){}
txtMsg.append(msgUtf8Str + "\n");