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:

https://bugs.java.com/bugdatabase/view_ bug.do?bug_ id=4163515

https://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding/362006#362006

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

http://happygiraffe.net/blog/2009/09/24/java-platform-encoding/

Similar Posts: