java打印unicode字符到bash shell(mac OsX)

luc*_*uca 2 java unicode bash utf-8 character-encoding

我在java 1.6中有这个代码:

System.out.println("\u00b2");
Run Code Online (Sandbox Code Playgroud)

但是在OSX10.6上的bash上我得到问号而不是unicode字符......

实际上我想在扩展的ascii代码上打印字符176,177,178(在这里查看http://www.asciitable.com/)在bash终端上创建一些艺术品.

任何的想法?

谢谢

小智 5

以下代码适用于Mac OS X 10.6.7上启用UTF-8的Terminal.app:

# code taken from: 
# "Print Unicode characters to the Terminal with Java",
# http://hints.macworld.com/article.php?story=20050208053951714

echo '
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
class Test {
  public static void main (String[] argv) throws UnsupportedEncodingException {
  String unicodeMessage = "\u00b2\u2591\u2592\u2593";
  PrintStream out = new PrintStream(System.out, true, "UTF-8");
  out.println(unicodeMessage);
  }
}
' > test.java

javac test.java
java Test
Run Code Online (Sandbox Code Playgroud)