From: http://blog.csdn.net/uestcong/article/details/6635123
1. Modify eclipse settings
The configuration file is used in the project, so a new. properties file is created in eclipse. The file is edited in Chinese and the following error is reported during saving:
Solution:
Select in sequence:
Menu --> preferences --> General --> contenttypes --> text --> JAVA properties file, set default encoding, change the following ISO-8859-1 to UTF-8 or GBK (recommended UTF-8), then update, as shown in.
2. format conversion in Java code
After the above steps, the file can be saved in UTF-8 format, but then there is a problem.
The Code is as follows:
[Java]View
Plaincopy
- // Load from the configuration file
- Configuration cfg = new Configuration ("etc/orgInfo. properties ");
- String _ orgName = cfg. getValue ("ORGNAME ");
- System. out. println ("before format change" + _ orgName );
The result is as follows: change the format of the prefix "çμ ç ç§ æ å ¤ *************************
It is certain that the file is converted to another format after being read, but the reason has not been found yet.
Therefore, the following changes were made:
[Java]View
Plaincopy
- Configuration cfg = new Configuration ("etc/orgInfo. properties ");
- String _ orgName = cfg. getValue ("ORGNAME ");
- System. out. println ("before format change" + _ orgName );
- // The encoding format must be converted. Otherwise, garbled characters will occur.
- String cn_orgName = new String (_ orgName. getBytes ("ISO-8859-1"), "UTF-8 ");
- OrgName. setAttribute ("value", cn_orgName );
The output result is as follows:
Change the format of the prefix "C. ç §?"?
E-Science and Technology College Hospital after the format change