5

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:

enter image description here

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)
Makoto
  • 104,088
  • 27
  • 192
  • 230
mre
  • 43,520
  • 33
  • 120
  • 170
  • I don't know what you're doing wrong but I get `中文` – Andy Nov 08 '11 at 20:55
  • I'm using Eclipse 3.6.1 Helios, by the way. – mre Nov 08 '11 at 21:00
  • Your platform use UTF-8 as the encoding? – Thorbjørn Ravn Andersen Nov 08 '11 at 22:10
  • 2
    I don't have that font. It works for me with Lucida Console and Courier New on Win7 x64. – BalusC Nov 09 '11 at 13:47
  • @BalusC, Yeah..I downloaded it haha. But it turns out that Arial Unicode MS works as well. – mre Nov 09 '11 at 13:49
  • 1
    Can also. I only don't like sans serif on stdout. Please note that `PrintStream out = new PrintStream(System.out, true, "UTF-8");` in your example is **unnecessary**. Just do `System.out.println(new Locale("zh", "CN").getDisplayLanguage(Locale.SIMPLIFIED_CHINESE));`. – BalusC Nov 09 '11 at 13:51

2 Answers2

5

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

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • I do not know. To my understanding, international versions of the JDK have much larger fonts than US-only. This is most likely for this exact reason. What platform are you using? – Thorbjørn Ravn Andersen Nov 09 '11 at 13:50
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.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • The encoding for the source file is already utf-8; same applies to the eclipse console. – mre Nov 09 '11 at 12:36