“VSCode无法从控制台读取 Cyrillic 字符。”

huangapple go评论76阅读模式
英文:

VSCode not reading Cyrillic from console

问题

以下是翻译好的内容:

问题是这样的,我开始使用VScode,但无法从控制台读取 Cyrillic 字符。

我的代码:

import java.util.Scanner;

class App {
    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in, "UTF-8");
        String word = input.nextLine();
        System.out.println(word);
    }
}

现在,当我输入任何 Cyrillic 字符串时,它会打印一个空字符串。如果我写像这样的内容:

System.out.println("Привет"); // Cyrillic symbols

它会打印出 "Привет",这是正常的。所以我猜测问题与读取字符串有关,而不是输出它。

chcp 命令显示 Active code page: 65001

我已经尝试设置编码并且不设置,但似乎不起作用,我是否漏掉了什么?

提前感谢。

英文:

Well, here is the problem, I have started using VScode, and I can't read from console cyrillic characters.

My code:

import java.util.Scanner;

class App {
    public static void main(String[] args) throws Exception {
      Scanner input = new Scanner(System.in,  "UTF-8");
      String word = input.nextLine();
      System.out.println(word);
    }
}

Now when I enter any cyrillic string it will print empty string back to me. If i write something like

System.out.println("Привет"); //cyrillic symbols

It will print "Привет", which is fine. So I am guessing it has something to do with reading the string rather than outputing it.

chcp command gives Active code page: 65001

I have tried setting encoding and without it, but it doesn't seem to work, is there something I missed?

Thanks in advance

答案1

得分: 2

我已在我的计算机上测试了代码,并得到了相同的结果:没有显示任何内容;

您可以看到,当在外部的 Windows PowerShell 或命令提示符中运行它时,结果是不同的,但仍然没有正确显示:

“VSCode无法从控制台读取 Cyrillic 字符。”

当我们将编码样式更改为GBK(936)时,西里尔字符可以正确显示:

“VSCode无法从控制台读取 Cyrillic 字符。”

当我们尝试更改在 VS Code 中集成终端的编码样式并再次执行代码时,仍然没有显示任何内容:

“VSCode无法从控制台读取 Cyrillic 字符。”

关于外部命令提示符和 VS Code 中集成终端之间的这些不同结果,我已经提出了一个 GitHub 请求。我正在进行一些研究,如果我得到了任何有用的信息,我会更新给您。

英文:

I've tested the code on my machine and got the same result: nothing shown;

You can see, when run it in external Window PowerShell or Command Prompt, the result is different but still not shown correctly:
“VSCode无法从控制台读取 Cyrillic 字符。”

When we change the encode style to GBK(936), the cyrillic characters can be displayed correctly:

“VSCode无法从控制台读取 Cyrillic 字符。”

When it comes to changing integrated terminal encoding style in vscode and execute code again, it still shows nothing:
“VSCode无法从控制台读取 Cyrillic 字符。”

About these different results between external Command Prompt and integrated terminal in VS Code, I've put a github request. And I'm doing some research, if any useful imformation i get, i will update you.

huangapple
  • 本文由 发表于 2020年10月17日 00:46:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/64393279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定