Java property file Chinese Solution

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.