开发者

java print unicode characters to bash shell (mac OsX)

I have this code in java 1.6:

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

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

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 b开发者_如何学Goash terminal..

any idea?

thanks


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


Is bash in a UTF8 locale? Type in the locale command and see if your LANG looks appropriate (e.g. something like *en_GB.UTF-8*). If not, update the value of LANG and try again.


First of all, you need to be certain that the character encoding in your terminal session matches what your java application is outputting. You most likely want UTF-8 which I believe is standard under OS X.

Next you need to be certain that the font used in your terminal session actually contains the characters you want to see. These seem to be rare and may not be available in all fonts.


Verify that Terminal > Preferences > Encodings has UTF-8 checked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜