Robz
Robz

Reputation: 1767

How to *easily* display Korean characters in a Java program

I'd like to do this:

System.out.println("안녕하세요!");

But I get a "Some characters could not be encoded using the MacRoman character encoding" popup error message when I try to compile in Eclipse. I'm running Mac OS X. Is there a way to get around that?

So, I guess I'll try using Unicode:

System.out.println((char)0xD0A4);

Which I'd like to print out '키', but instead get a '?'. I guess the command line doesn't support Unicode. But even if it did, it'd be really annoying to have to go to one of several charts (like this one) to find each character block.

Anyway, FINE! So I'll use a JLabel...

JLabel lbl = new JLabel(""+(char)0xD0A4);

Awesome, this prints out 키! ... but I still have to look up the Unicode characters for each block. How can I easily spew out Korean characters in a program?

Upvotes: 2

Views: 9273

Answers (3)

Urs Reupke
Urs Reupke

Reputation: 6921

Switch to UTF-8, as said before. However, instead of doing it on a per-project basis (as J-16) suggests, go through Window -> Preferences -> General -> Workspace and change the "Text file encoding" to "Other: UTF-8".

This changes the setting for the entire workspace. Afterwards, you can input your characters as you are used to.

Upvotes: 5

J-16 SDiZ
J-16 SDiZ

Reputation: 26910

Just right click the file in the project view, choose properties. Change the encoding to UTF8 there.

Upvotes: 1

kevmo314
kevmo314

Reputation: 4317

The Eclipse console doesn't use unicode encoding so it can't display those. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=13865.

Try the fix mentioned here: http://paranoid-engineering.blogspot.com/2008/05/getting-unicode-output-in-eclipse.html

Upvotes: 1

Related Questions