Home > Java > JavaBase > body text

Solution to Java compilation garbled code

Release: 2019-11-22 14:54:42
Original
4435 people have browsed it

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, 你好");  
  }
}
Copy after login

Compile command:

javac -d . Run.java
Copy after login

Execution command:

java com.test.Run
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template