Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

java - Windows 10 CLI UTF-8 encoding

Problem:

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. )

Tested in:

  • CMD, Powershell, Cmder on Windows 10 64-bit English - Slovenian keyboard layout ... unsuccessful
  • Intellij IDEA on Windows 10 64-bit English language - Slovenian keyboard layout ... successful -> Works as needed in IDE, but not CLI.
  • CMD Windows 10 64-bit English language - English keyboard ... successful
  • CMD Windows 10 64-bit Slovenian languge - Slovenian keyboard layout ... succesful
  • Several distros of Linux (Ubuntu, Mint, Kali) ... successful

Tried so far:

  • changing chcp to chcp 65001 ... unsuccessful
  • creating Autorun file in regedit to force UTF-8 ... unsuccessful
  • different java compilers ... unsuccessful

Sample code:

public class Test2 {
public static void main(String[] args) {
    System.out.println("? ? ? ? ?");

    }
}

CMD:

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

Other notes:

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...