unicode characters appear as question marks in IntelliJ IDEA console

后端 未结 8 2125
粉色の甜心
粉色の甜心 2020-12-11 15:26

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

8条回答
  •  既然无缘
    2020-12-11 15:44

    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");

提交回复
热议问题