Special characters in properties file

ぃ、小莉子 提交于 2019-12-12 15:14:02

问题


In my Java/Spring web application i had problem printing special characters of italian language (ò,à,è etc.) that I retrieve from a properties file.

I found this article http://docs.oracle.com/cd/E26180_01/Platform.94/ATGProgGuide/html/s1816convertingpropertiesfilestoescap01.html.

But something is not clear: after I run the command written in the article, in my console (CMD console of windows) i can read my properties file "translated". After it, what should i do?

Should I copy the texts from the windows console and paste them into my properties file? It doens't seem a "professional" work!


回答1:


There's no need in copying the output, you may just redirect it to the file:

native2ascii notTranslated.properties > translated.properties

Also, if you're building your project with Ant, you can use native2ascii ant task, for example:

<native2ascii src="srcdir" dest="srcdir" includes="**/*._properties" ext=".properties"/>

I assume here, that the initial non-ASCII properties files are named *._properties in your project.




回答2:


The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped '=', ':', or white space character other than a line terminator. All of these key termination characters may be included in the key by escaping them with a preceding backslash character; for example,

\:\=

would be the two-character key ":=". Line terminator characters can be included using \r and \n escape sequences. Any white space after the key is skipped; if the first non-white space character after the key is '=' or ':', then it is ignored and any white space characters after it are also skipped. All remaining characters on the line become part of the associated element string; if there are no remaining characters, the element is the empty string "". Once the raw character sequences constituting the key and element are identified, escape processing is performed as described above.

See this link to escape special char and see this link to read by different UTF.



来源:https://stackoverflow.com/questions/25969036/special-characters-in-properties-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!