java display read properties garbled solution

 

  1 java reads some self-written properties configuration files, if it contains Chinese, it needs to be read or stored by transcoding

There are two common methods:
① Use the java command line tool native2ascii, this method is transcoding storage.
② When java reads the properties key, it uses transcoding new String( key.getBytes("ISO-8859-1"), "gbk" ), this method is transcoding reading.
The advantage of the first method is that there are no obstacles when writing. The disadvantage is that it is troublesome when deploying. It needs to be transferred with commands and then put into the project. If the content of the file is frequently changed, it is very annoying.
The advantage of the second method is that there is no obstacle when writing key-value pairs, and there is no need to manually change the encoding when deploying, but the reading method needs to be changed in the java code, and the transcoding during reading is also very time-consuming.
 

2 So is there a way to transcode without changing the code when reading, or manually transcoding when storing?

The answer is yes. Myeclipse's own editor, myeclipse properties editor, can be used to open the properties file in the project (the default opening method), and then select the properties tab. At this time, you can see neatly arranged key-value pairs, only You just need to fill in the value, myeclipse will automatically convert to ascii encoding to store.
 
what if there is no myeclipse
Use the UltraEdit editor to write the Chinese configuration file prop_cn.properties, click Save As after saving, the file name is prop.properties, and the encoding can be selected as unicode ascii.
 
Reprinted from: http://blog.sina.com.cn/s/blog_74a86d520101aj24.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324709609&siteId=291194637