Displaying chess pieces using unicode in eclipse using java

I'm just trying to display some unicode characters in eclipse using java, however it just prints random rectangles, and if chess pieces haven't changed style recently, I don't think this is what I want. Help is much appreciated!

my code is:

import java.io.PrintStream; import java.io.UnsupportedEncodingException; public class ChessSymbols { public static void main (String [ ] args)throws UnsupportedEncodingException { String unicodeMessage = "\u2654 " + // white king "\u2655 " + // white queen "\u2656 " + // white rook "\u2657 " + // white bishop "\u2658 " + // white knight "\u2659 " + // white pawn "\n" + "\u265A " + // black king "\u265B " + // black queen "\u265C " + // black rook "\u265D " + // black bishop "\u265E " + // black knight "\u265F " + // black pawn "\n" ; PrintStream out = new PrintStream (System.out, true , "UTF8" ); out.println(unicodeMessage); } } 
+7
source share
4 answers

If you use the Eclipse launch configuration to run your code, you need to set the character encoding in the console dialog box. You can do this (I'm checking Indigo, I'm not sure about earlier versions) by creating Run Configurations, selecting the given Java execution command, clicking on the Common tab, and on the right is the way to choose console character encoding (which is very important for UTF8 for your program )

I found this by typing "encoding for console" in the search help dialog box.

+3
source

In Eclipse, click Run → Run Configuration. → General tab → Encoding → Other: UTF-8: this is fixed here

I am running Version: Helios Service Release 2, Build id: 20110218-091 on Windows 7.

You may also need to use the command line.

This is a problem with the Eclipse console. Please review this article, you need to edit eclipse.ini - http://paranoid-engineering.blogspot.com/2008/05/getting-unicode-output-in-eclipse.html

+2
source

I tried your code and it works correctly on my Linux. Tried this from an empty shell and from Eclipse. This is not a Java problem, but a console encoding problem. You should look into the encoding your console accepts and make sure that it is UTF8. Eclipse should not consider this.

+1
source

Most likely, the font does not have the glyphs you need. Try changing the console font.

+1
source

All Articles