Java将unicode字符打印到bash shell(Mac OsX) [英] java print unicode characters to bash shell (mac OsX)

查看:157
本文介绍了Java将unicode字符打印到bash shell(Mac OsX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java 1.6中有以下代码:

I have this code in java 1.6:

System.out.println("\u00b2");

但是在OSX10.6的bash上我收到问号,而不是Unicode字符...

but on bash on OSX10.6 I get question marks and not the unicode characters...

实际上,我想在扩展的ascii代码上打印字符176,177,178(请在此处 http://www.asciitable.com/)在bash终端上创建一些图片.

actually I want to print the characters 176,177,178 on the extended ascii code (look here http://www.asciitable.com/) to create some art on the bash terminal..

有什么主意吗?

谢谢

推荐答案

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

The following code works for me in UTF-8 enabled Terminal.app on Mac OS X 10.6.7:

# 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

这篇关于Java将unicode字符打印到bash shell(Mac OsX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆