The problem that Java code is garbled when executed at the Windows command prompt. There are two ways to do it, so I will introduce it !!
It seems that the character settings of the text editor and the command prompt are different.
At the bottom of the "Options" tag in the command prompt properties,
The current code page is 932 Shift-JIS
.
However, when I look at Encoding from the VScode settings, it is ʻurf8`, so it may have been garbled because it does not fit.
So this time I will set it according to VS code.
--People programming on Windows --Java beginner --I'm using VScode.
The CHCP command is a command that can be used to set the character code. You can change it by specifying chcp <code page number>
, and the command prompt setting will also change.
If you want to use the same UTF-8 as VScode, type chcp 65001
at the command prompt to switch the screen.
After that, if you compile as usual and the characters are not garbled after execution, it is successful!
javac Sample1.java
java Sample1
Hello, Java!
How to run with command line options. This is fine, but for those who are tired of attaching it, the above method is good!
javac Sample1.java -J-Dfile.encoding=UTF-8
java Sample1 -J-Dfile.encoding=UTF-8
Hello, Java!
When I execute java code, it becomes characters Windows command prompt character code setting Character code settings
Recommended Posts