Properties file encoding issues in eclipse

Source: Internet
Author: User

1. Eclipse Modify Settings

The configuration file was used in the project, so a new. Properties file was created in Eclipse, the Chinese was edited in the file, and the following error was reported when saving the eclipse:

Ways to solve this problem:

Select:

Menu-->preferences-->general-->contenttypes-->text-->javaproperties File, set default encoding, Change the following iso-8859-1 to UTF-8 or GBK (recommended UTF-8), and then update as shown.

2. Format conversion in Java code

After you perform the above steps, the file can be saved in UTF-8 format, but then there is a problem with it.

The code is as follows:

    // Loading from the configuration file    New Configuration ("Etc/orginfo.properties");     = Cfg.getvalue ("OrgName");    System.out.println ("pre-format" + _orgname);

The resulting output is: Before changing the format?? μ?-?? §????? ¤§?-|? ???? É?¢

To be sure, the file is formatted and converted somewhere after it has been read, but no reason has been found so far.

Therefore, the following modifications were made:

    New Configuration ("Etc/orginfo.properties");     = Cfg.getvalue ("OrgName");    System.out.println ("pre-format" + _orgname);     // encoding format conversion is required, otherwise it will be garbled    New String (_orgname.getbytes ("iso-8859-1"), "Utf-8");    Orgname.setattribute ("value", cn_orgname);

The output at this time is:

Before you change the format?? μ?-?? §????? ¤§?-|? ???? É?¢
After the change of the format of University Hospital

This article was transferred from: http://blog.csdn.net/uestcong/article/details/6635123

Properties file encoding issues in eclipse

Related Article

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.