Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unicode characters appear as question marks in IntelliJ IDEA console

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 of question marks?

I'm using IntelliJ IDEA on Windows, and trying to print from within the IDE.

like image 872
Eran Avatar asked Jul 04 '09 14:07

Eran


People also ask

How do I get special characters in IntelliJ?

How to show tabs and white space characters in IDEA? To enable this feature in IntelliJ, you must open the Settings dialog ( Ctrl+Alt+S ) and navigate to the Editor | General | Appearance tab. In this tab you need to enable the Show whitespace option.

What is the Unicode for a question mark?

In computing, the question mark character is represented by ASCII code 63 (0x3F hexadecimal), and is located at Unicode code-point U+003F ? QUESTION MARK ( ?).


2 Answers

Go to Help > Edit Custom VM options... then add the following option:

-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8

I'm not sure if both are necessary but it worked for me. You need to restart IntelliJ for changes to be applied.

I had already tried changing every encoding setting in Intellij, setting those options in Gradle and changing the system encoding, this is the only one that worked.

like image 76
Nicolas Avatar answered Oct 09 '22 20:10

Nicolas


A little update for the year 2015

TL;DR answer:

Go to Settings -> Editor -> File Encodings -> Project Encoding and set it to "UTF-8".

Expanded answer:

The reason why it does not work can be found by placing a breakpoint on a System.out.print() call. When the breakpoint hits, you can add System.out to Watches, and you can see that System.out.textOut.out.se.cs is set to windows-1252 or something similarly unsuitable.

The setting which magically worked for me (I do not know why) is in Settings -> Editor -> File Encodings -> Project Encoding. You need to set that to "UTF-8".

Then, unicode characters display properly on the console, and one more quick look with the debugger shows that the value of System.out.textOut.out.se.cs has magically turned into UTF-8.

I am saying "magically" because I do not see how and why an editor setting should affect the character set that System.out gets instantiated with when launching/debugging an application. If someone knows what is the logic behind this, please do tell!

like image 31
Mike Nakis Avatar answered Oct 09 '22 19:10

Mike Nakis