Home  >  Article  >  Java  >  Solution to Java compilation garbled code

Solution to Java compilation garbled code

尚
Original
2019-11-22 14:54:424433browse

Solution to Java compilation garbled code

When Java compiles source code, it will obtain the codepage from the operating system by default. If you accidentally install the English version when installing the operating system, garbled codes may be generated when compiling the java source code. .

Please look at the test code below:

package com.test;
public class Run {
  public static void main(String[] args) {
    System.out.println("hello, 你好");  
  }
}

Compile command:

javac -d . Run.java

Execution command:

java com.test.Run

If you compile under the command line codepage 437 (English) Garbled characters will appear.

It is OK if compiled under the command line codepage 936 (GBK).

If such an operating system environment is used, the source code will be garbled in Eclipse, with serious consequences.

1. Java can be compiled through parameters to eliminate garbled code.

javac -encoding gbk -d . Run.java

2. Modify the locale configuration of the entire operating system.

For more java knowledge, please pay attention to java basic tutorial.

The above is the detailed content of Solution to Java compilation garbled code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn