I\'m trying to write unicode characters (♠) using System.out, and a question mark gets printed instead.
How can I have proper unicode characters displayed instead o
Do you have the appropriate fonts installed on your machine? The question mark appears when you don't have fonts for the characters you're outputting.
Also, are you outputting by doing a System.out.println("
? If so, just installing the fonts should work.
If you are trying to write to System.out
from within your program, that's different. You have to use an OutputStreamWriter
, which is a character stream. You can't just write to a byte-oriented stream such as OutputStream
.
Look up the API and class reference for OutputStreamWriter
and subclasses such as PrintWriter
. You construct it giving the locale of the constructor. For example,
PrintWriter pw = new PrintWriter(System.out, "UTF-8");