The Java Read properties file contains two main types of Chinese characters:
1.key contains Chinese characters (which may also be included in value)
2.key does not contain Chinese characters (it is possible to include in value)
1. Key contains Chinese characters
You can use the Java native2ascii.exe tool (Java\jdk1.x.x\bin\native2ascii.exe) to convert the file encoding format
Example: native2ascii-encoding 8859_1 c:\a.properties c:\b.properties
The C:\a.properties file contents will be 8859_1 transcoded, saved as c:\b.properties file.
Command format: Native2ascii-[options] [inputfile [OutputFile]]
Parameter option Options-reverse: Convert Latin-1 or Unicode encoding to local encoding-encoding encoding_name: Specify the encoding to use when converting Inputfile: file to convert outputfile: converted File
Reciprocal (-encoding, non-English content (such as Chinese) to convert between coded or encoded characters)
Reversal (-reverse, usually converting a coded character to a non-English content, or a conversion between non-English content)
The file encoding and local encoding to be reversed should be consistent:
Example: After converting Chinese to ISO 8859_1 encoding, convert the 8859_1 code to Chinese:
Native2ascii-encoding 8859_1 C:\a.txt C:\b.txt,
Transcode A with 8859_1 and save as B (8859_1 code)
Native2ascii-encoding GBK C:\b.txt C:\c.txt,
Transcode B with GBK and Save as C (GBK code)
Native2ascii-reverse C:\c.txt C:\d.txt,
GBK encoding c with local code transcoding, save as D (Chinese content) Chinese to GBK encoding, the GBK code to Chinese:
Native2ascii-encoding GBK C:\a.txt C:\b.txt,
Transcode A with GBK and save as B (GBK code)
Native2ascii-reverse C:\b.txt C:\c.txt,
GBK encoded B with local code transcoding, save as C (Chinese content)
After doing this, read the key contains the Chinese properties, you need to have the following conversion code:
String value = "China";
String value2 = new String (Value.getbytes (), "iso-8859-1");
System.out.println (P.getproperty (value2));
2.key does not contain Chinese characters, in value
Direct use of 1 in:
String value = P.getproperty (key);
String value2 = new String (Value.getbytes ("iso-8859-1"), "GBK");
How to solve the problem of garbled characters in Java read properties file