java 属性文件中的特殊字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25969036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:03:54  来源:igfitidea点击:

Special characters in properties file

javaspringjsppropertiesproperties-file

提问by MDP

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". After it, what should i do?

但有些事情并不清楚:在我运行文章中写的命令后,在我的控制台(Windows 的 CMD 控制台)中,我可以读取我的属性文件“翻译”。之后,我该怎么办?

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

我应该从 Windows 控制台复制文本并将它们粘贴到我的属性文件中吗?这似乎不是一个“专业”的工作!

回答by Dmitry Ginzburg

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 native2asciiant task, for example:

此外,如果您使用 Ant 构建项目,则可以使用native2asciiant 任务,例如:

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

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

我在这里假设初始非 ASCII 属性文件*._properties在您的项目中命名。

回答by Xstian

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.

将是两个字符的键“:=”。可以使用 \r 和 \n 转义序列包含行终止符。跳过键后的任何空格;如果键后的第一个非空白字符是“=”或“:”,则忽略它,并且也跳过它后面的任何空白字符。该行所有剩余的字符成为相关元素字符串的一部分;如果没有剩余字符,则元素为空字符串“”。一旦识别出构成键和元素的原始字符序列,就如上所述执行转义处理。

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

请参阅此链接以转义特殊字符并查看此链接以通过不同的 UTF 读取。