简体   繁体   English

属性文件中的特殊字符

[英]Special characters in properties file

In my Java/Spring web application i had problem printing special characters of italian language (ò,à,è etc.) that I retrieve from a properties file. 在我的Java / Spring Web应用程序中,我遇到了从属性文件中检索的意大利语(ò,à,è等)特殊字符的问题。

I found this article http://docs.oracle.com/cd/E26180_01/Platform.94/ATGProgGuide/html/s1816convertingpropertiesfilestoescap01.html . 我发现这篇文章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". 但有些事情并不清楚:在我运行文章中写的命令之后,在我的控制台(Windows的CMD控制台)中,我可以读取我的属性文件“已翻译”。 After it, what should i do? 在它之后,我该怎么办?

Should I copy the texts from the windows console and paste them into my properties file? 我应该从Windows控制台复制文本并将其粘贴到我的属性文件中吗? It doens't seem a "professional" work! 它似乎不是一个“专业”的工作!

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: 此外,如果您使用Ant构建项目,则可以使用native2ascii ant任务,例如:

<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. 我在这里假设,初始的非ASCII属性文件在项目中被命名为*._properties

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. 可以使用\\ r和\\ n转义序列包含行终止符字符。 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. 请参阅此链接以转义特殊字符,并查看此链接以通过不同的UTF读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM