1. Principle
In the Property file, the encoding method used may be GBK or UTF-8 Based on the machine's own settings. In JavaProgramThe Unicode encoding method is used to read the property file. Different encoding methods may cause Chinese garbled characters. Therefore, you must convert Chinese characters in the property file into unicode encoding to display Chinese characters normally.
2. Solution
Java provides a dedicated tool for Unicode conversion to the property file. This tool is native2ascii, which is located in the bin directory of the JDK installation environment.
The native2ascii tool converts a file with native encoding characters (non-Latin 1 and non-single-code characters) into a file with Unicode encoding characters.
Assume that the property file to be converted is: D:/src/resources. properties (contains Chinese characters)
The converted property file is: D:/classes/resources. properties (Chinese characters are converted to Unicode)
Use the following command
Java_home/bin/native2ascii-encoding gbk d:/src/resources. properties D:/classes/resources. Properties
You can convert an attribute file containing Chinese characters into an attribute file in a single unicode encoding mode. Chinese garbled characters will naturally be resolved.