javavisual-studio-code

VSCode Java UTF-8 does not print characters to the console


I have a problem with encoding Java System Output occurring only in Visual Studio Code.

Like you can see in the image below bullet print as ?

Eclipse and IntelliJ print the bullet point just fine.

My program is very simple: enter image description here

Things I have tried/checked:

  1. chcp: List item

  2. UTF8 is set: enter image description here

  3. I only have the Java Extension Pack by Microsoft installed.

  4. It is a fresh new file created from VScode.

  5. The chcp inside VSCode terminal is Active code page: 65001 enter image description here


Solution

  • The UTF-8 displayed in the lower right corner of VS code is the encoding format of the current file, not the encoding format of the terminal.

    You should check the encoding by typing chcp in the terminal of VS code.

    The encoding format of the terminal in vscode may be different from the system's cmd and powershell encoding.

    So please check the encoding format in the terminal in VS code, not in the cmd or powershell window of the system

    Here is my test display:

    my code:

    public class App {
        public static void main(String[] args) {
            System.out.println("example ●");
        }
    }
    

    The encoding format of the system cmd window is 65001

    enter image description here

    The encoding format of the system powershell window is 65001

    enter image description here

    But the terminal encoding in vscode is 437

    enter image description here

    Run the result directly ( Can't display symbols )

    enter image description here

    So you need to use chcp 65001 to change the current terminal encoding format in VS code.

    then run the code ( success display symbol)

    enter image description here

    But this still has problems, every time you open a new terminal, you need to manually type the command chcp 65001 to change the encoding format.

    I found a way in my constant search. Add the following configuration in settings.json:

        "terminal.integrated.shellArgs.windows": ["-noexit", "chcp 65001"]
    

    A yellow squiggly line will appear indicating that this configuration is out of date and there are now new configuration commands. Never mind, this still works. If you want to see the new configuration, here.

    Note: After adding this configuration, you need to restart VS code to take effect.

    In this way, when you create a new terminal, you will automatically use the command chcp 65001 to change the encoding to 65001

    enter image description here

    Now run the code directly, the symbols can be displayed

    enter image description here