After the JVM is started, setting the system property file.encoding again cannot affect the default encoding of the system & sun.jnu.encoding

Causes and solutions: id=4163515

Who sets file. Encoding

First, file. Encoding is a system property. It can be set before starting the JVM, such as:

  java -Dfile.encoding=UTF-8 xxx.class

Another way is to change the system region of the operating system, because if this property is not set when the JVM starts, the encoding mode is selected according to the system region (locale) by default

When the region is China, the file.encoding is GBK region

When the region is the United States, the file.encoding is cp1252 region


In JDK1.8, only four references to file. Encoding are found

The default encoding method of JVM: charset. Defaultcharset ()

Function of sun.jnu.encoding: used to parse command line parameters, classes containing main methods, and environment variables

Similar Posts: