1

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

David
  • 145
  • 1
  • 3
  • 13
  • 1
    I am pretty sure the UTF8 you see in the bottom bar correspond to the current active source-file charset, not the console's one. A quick google-search found me a github thread including this comment: https://github.com/Microsoft/vscode/issues/19837#issuecomment-290843303. I suspect you put that in the `settings.json` file. Might wanna give that a try – n247s Aug 04 '22 at 11:32
  • Anyone else could guide me on what to do to solve this problem? – David Aug 04 '22 at 12:12

1 Answers1

2

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

JialeDu
  • 6,021
  • 2
  • 5
  • 24
  • I just checked the vscode terminal chcp and it says Active code page: 65001 and I still have the problem anything else I can check? – David Aug 05 '22 at 10:04
  • Can you provide the jdk version you are using? and the version number of vscode. – JialeDu Aug 08 '22 at 09:27
  • I have no idea what was the problem but I just reinstall vscode and now it is working – David Aug 08 '22 at 11:59
  • 1
    *"this configuration is out of date"* - you can see the new configuration in the [answer here](https://stackoverflow.com/a/74665369/2189130). – kmdreko Jan 08 '23 at 17:09