Search code examples
javavisual-studio-codeterminalencodingcharacter-encoding

VS Code terminal doesn't print correctly all characters in my java code


I have this simple code that should print these characters

public class App {
    public static void main(String[] args) throws Exception {
        System.out.print("名 é à è €");
    }
}

But whenever I run and debug in VS Code my project, the output in the terminal is this:

screenshot ? é à è ?

I tried to enter chcp 65001 to fix it but it does not correct the isssue and here's the output after:

ÕÉì + line drawing characters etc

I tried to do these things outside of VS Code by doing javac and java and this is what I got:

Without chcp 65001:

? é à è ?

With chcp 65001:

名 é à è €

Here's my javac version: javac 22.0.1


Solution

  • this issue could be the cause of the coding error. By default, vscode uses UTF-8 encoding, and the computer uses GBK. I tried changing the computer settings to work fine:

    1. Go to the computer settings, select Time&Language, select Language&region, Administrative language settings, Change system locale, and tick the Beta version.
    2. Restart vscode to try to run the code. enter image description here