Solution: First use software to open the java file; then use the "ctrl a" key to select all the code in the file, and use the "ctrl c" key to copy the code; then click "Encoding" at the top of the page, and select Select "Use ansi encoding" in the list and use the "ctrl v" key to paste the code; finally save and run.
The operating environment of this tutorial: windows7 system, java10 version, Dell G3 computer.
When such an error occurs, it is usually because the code contains Chinese characters, and the Chinese characters in the comments are also counted. Because when using CMD to run a java program, the system's default encoding format is gbk. Codes containing Chinese characters are generally in UNICODE format, so it is easy to cause coding errors when running codes containing Chinese characters directly.
It is easy to solve the problem once you know the source of the problem. For those who use notpad, you can directly use the transcoding function that comes with the editor.
The encoding conversion position is in the Encoding column. Just convert the encoding to "Use ANSI format encoding".
But if we directly click "Use ANSI format encoding", we will find that the original Chinese characters are garbled, which is obviously not the effect we want.
The correct way is to copy all the source files first, then delete all the codes, and then set the encoding format to "Use ANSI format encoding". After setting Then paste the source file and save it. At this time, you will find that the encoding is in ANSI format.
After modification, we run it again and it works perfectly.
Related free learning recommendations:java basic tutorial
The above is the detailed content of How to solve the unmappable characters in java encoding gbk. For more information, please follow other related articles on the PHP Chinese website!