How to print [Simplified] Chinese characters to Eclipse console?

╄→гoц情女王★ 提交于 2019-12-07 06:04:42

问题


I have the following code:

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Locale;

public final class ChineseCharacterDemo {

    public static void main(String[] args) throws UnsupportedEncodingException {
        Locale locale = new Locale("zh", "CN");
        System.out.println(locale.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE));
    }

}

And even after setting the character encoding of the Eclipse console to UTF-8, I get boxes, instead of the following:

中文

What am I doing wrong?


EDIT-

After changing the Eclipse console font to something capable of rendering Chinese characters, I get the following, incorrect, display:

But, when I copy/paste the text here, it correctly renders the Simplified Chinese text. Again, what's going on here? Actually, if you look at the rendered text in the console, it's the correct characters, but they're on their side!


Resolution-

So, it turns out that I needed to do the following:

  1. Change character encoding of Eclipse console to UTF-8
  2. Change font to Arial Unicode MS (i.e. any font capable of rendering Chinese text)

回答1:


Change the font for the Console to one which actually contains the Chinese characters you need to see.




回答2:


here I copied your class and did a test.

if the .java file encoded with utf-8, it shows

中文

otherwise, (iso-8859-1 for example) it shows something like

中æ

so maybe you could try to set the encoding of your java source file to utf-8.



来源:https://stackoverflow.com/questions/8056900/how-to-print-simplified-chinese-characters-to-eclipse-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!