【问题标题】:How can I print Vietnamese in the terminal in VS Code?如何在 VS Code 的终端中打印越南语?
【发布时间】:2022-01-05 23:15:42
【问题描述】:

这是我的代码:

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

在 VS Code 终端中打印:

Ti?ng Vi?t có d?u

如何修复它,以便 VS Code 终端正确显示文本?

【问题讨论】:

  • 我相信这可能是 VS Code 本身而不是 Java 的行为。请尝试将您在 VS Code 中的语言环境/语言更改为越南语(按照这些步骤code.visualstudio.com/docs/getstarted/locales,请注意目前没有正式支持的越南语言环境,但可能另一种语言共享字符集/字母表)。
  • 是的,我觉得 VS Code 出了点问题,我只是用 java 给你看,以前我用过 VS 但他们仍然用越南语打印,但现在他们没有,我不知道他们错了,我使用 Python 他们可以工作,但 Java 和 C 不行

标签: java visual-studio-code terminal


【解决方案1】:

假设 Windows >= 10:

  1. + R, intl.cpl, 回车

  2. 这样做:

  1. 正在重启系统。

See here/Thank You!


然后(重启后)我们在 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!

(确保):

See Also.


...我们得到(运行 Java,默认 shell,在我的例子中是 pwsh.7.2.0):

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> 

...但也切换到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?!? - “空问题”:

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

所以问题不在于 VS Code 或 Java,而在于更“一般”/历史/“专有”(请参阅​​链接的线程 + What encoding/code page is cmd.exe using? + https://www.google.com/search?q=windows+console+encoding :)

因为在 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

!! ;)

【讨论】:

    猜你喜欢
    • 2019-03-13
    • 2018-04-28
    • 2021-04-26
    • 1970-01-01
    • 2021-11-20
    • 2022-01-09
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    相关资源
    最近更新 更多