Friday, March 21, 2008

Print UTF-8 Characters in Eclipse Console

In eclipse, "Run Dialog", "Common" tab, change "Console Encoding" to UTF-8. The code below should print some CJK characters.


import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class TestClass {

public static void main(String [] args) throws UnsupportedEncodingException {
String chineseString = "\u4e00\u4e01\u4e02\u4e03\u4e04";
PrintStream ps = new PrintStream(System.out, true, "UTF-8");
ps.println(chineseString);
}
}

No comments: