2

This is my code:

public class Test {
   public static void main(String[] args) {
      System.out.println("Tiếng Việt có dấu");
  }
}

In the VS Code terminal it prints:

Ti?ng Vi?t có d?u

How can I fix it so the VS Code terminal displays the text correctly?

Tim
  • 5,435
  • 7
  • 42
  • 62
  • 1
    I believe that this may be the behavior with VS Code itself rather than Java. Please try changing your locale/language in VS Code to Vietnamese (follow these steps https://code.visualstudio.com/docs/getstarted/locales, please note there is not currently a Vietnamese locale officially supported, but maybe another language shares a character set/alphabet). – Nick Clark Nov 29 '21 at 02:49
  • 1
    yes, i think something wrong at VS Code, i just use java to show for you, Before, I used VS but they still print in Vietnamese but now they don't, I don't know where they are wrong, im use Python they work but Java and C not – Quang Nguyễn Nov 29 '21 at 05:14

1 Answers1

1

Assuming Windows >= 10:

  1. Windows Key + R, intl.cpl, Enter

  2. doing this:

  1. Restarting system.

See here/Thank You!


Then (after Restart) we try this in VS Code:

public class Test {
  public static void main(String[] args) throws UnsupportedEncodingException {
    System.out.println("1: Tiếng Việt có dấu");
    try ( PrintWriter consoleOut = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8))) {
      consoleOut.println("2: Tiếng Việt có dấu");
    }
  }
}

See also/Thank You!

(Ensuring):

VS-Code, File Encoding, UTF-8

See Also.


... we get (Run Java, default shell, pwsh.7.2.0 in my case):

PowerShell 7.2.0
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\DEV\projects\test>  & 'C:\Program Files\Java\jdk1.8.0_311\bin\java.exe' '-cp' 'C:\Users\xerx\AppData\Local\Temp\cp_16pw9c0xw9lhctexolmzuqrp.jar' 'Test' 
1: Ti?ng Vi?t c d?u
2: Tiếng Việt có dấu
PS C:\DEV\projects\test> 

... but also switching to cmd.exe:

Microsoft Windows [Version 10.0.19044.1348]
(c) Microsoft Corporation. Alle Rechte vorbehalten.

C:\DEV\projects\test>java -cp C:\Users\xerx\AppData\Local\Temp\cp_16pw9c0xw9lhctexolmzuqrp.jar Test 
1: Ti?ng Vi?t c d?u
2: Tiếng Việt có dấu

GitBash?!? - "Null Problemo":

picard@enterprise MINGW64 /c/DEV/projects/test (main)
$ java -cp ~/AppData/Local/Temp/cp_16pw9c0xw9lhctexolmzuqrp.jar Test
1: Ti?ng Vi?t c d?u
2: Tiếng Việt có dấu

So the problem is rather not in VS Code or Java, but more "general"/historic/"proprietary" (see the threads linked + What encoding/code page is cmd.exe using? + https://www.google.com/search?q=windows+console+encoding :)

Because in Ubuntu (wsl) Shell:

picard@enterprise:/mnt/c/DEV/projects/test$ java -cp ./build/classes/java/main/ Test
1: Tiếng Việt có dấu
2: Tiếng Việt có dấu

!! ;)

xerx593
  • 12,237
  • 5
  • 33
  • 64