Mukhamedali  Zhadigerov
Mukhamedali Zhadigerov

Reputation: 861

Cannot display an unicode character on windows cmd using Java

My code:

class Test{
    public static void main(String[]args){
        char c = 'П';
        System.out.print(c);
    }
}

All I want is to display that character on windows cmd (which seems to be over-complicated issue for cmd as I've tried many different ways but could not succeed).

  1. I tried a straightforward way: javac Test.java, comiler throws this:

    Test.java:3: error: unclosed character literal char c = 'П';

  2. I tried javac -encoding UTF-8 Test.java. It compiles but the character does not appear in cmd.

  3. I tried to save Test.java with unicode and typed javac -encoding UTF-16 Test.java but the character still does not appear.

Also, I should use plain windows notepad and cmd only. Please help, I am struggling with this issue 2 days :(

Upvotes: 1

Views: 1467

Answers (1)

David Conrad
David Conrad

Reputation: 16359

Change the encoding cmd uses to UTF-8 with chcp 65001 and then run your Java program with Java's file encoding set to UTF-8:

java -Dfile.encoding=UTF-8 Test

Upvotes: 3

Related Questions