Windows 10 CLI UTF-8 编码 [英] Windows 10 CLI UTF-8 encoding

查看:34
本文介绍了Windows 10 CLI UTF-8 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

在使用斯洛文尼亚语键盘布局的英文 Windows 10 上,所有命令行界面似乎都无法显示(打印)UTF-8 字符,即 č、š 和 ž,这些字符被替换为 ?.(我假设所有 UTF-8 特定字符,因为 ć 和 đ 也不起作用.)

On an english Windows 10 using slovenian keyboard layout, all command line interfaces seem to have a problem with displaying (printing) UTF-8 characters, namely č, š and ž, which are replaced with ?. (I assume all UTF-8 specific characters, since ć and đ also do not work. )

测试:

  • Windows 10 64 位英语 - 斯洛文尼亚语键盘上的 CMD、Powershell、Cmder布局……不成功
  • Windows 10 64 位英语上的 Intellij IDEA - 斯洛文尼亚语键盘布局...成功 -> 在 IDE 中根据需要工作,但在 CLI 中不工作.
  • CMD Windows 10 64 位英语语言 - 英语键盘...成功
  • CMD Windows 10 64 位斯洛文尼亚语 - 斯洛文尼亚语键盘布局...成功
  • 多个 Linux 发行版(Ubuntu、Mint、Kali)......成功

到目前为止尝试过:

  • 将 chcp 更改为 chcp 65001 ...失败
  • 在 regedit 中创建自动运行文件以强制使用 UTF-8 ......失败
  • 不同的 Java 编译器...不成功

示例代码:

public class Test2 {
public static void main(String[] args) {
    System.out.println("č š ž ć đ");

    }
}

命令:

>javac -encoding UTF-8 test2.java
>java Test2
? ? ? ? ? 

其他注意事项:

问题出现在运行在不同硬件上的多台计算机上.默认情况下,所有上述字符在上述所有 CLI 中都可以正常工作.所以这个问题似乎只出现在java中.

Problem appears on several computers running on different hardware. All of the above mentioned characters work fine in all of the above mentioned CLI by default. So the problem only seems to appear with java.

推荐答案

使用 chcp 65001 然后用 java -Dfile.encoding=UTF-8 Test2 运行:>

Use chcp 65001 then run with java -Dfile.encoding=UTF-8 Test2:

chcp 65001
javac -encoding UTF-8 Test2.java
java -Dfile.encoding=UTF-8 Test2

记得在类名之后命名你的 Java 源文件,区分大小写.

Remember to name your Java source file after the class name, case-sensitive.

这篇关于Windows 10 CLI UTF-8 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆