sun*_*dev 5 encoding spring utf-8 iso-8859-1
我正在使用 Spring ResourceBundle 从我的 .properties 文件中检索消息包。它包含特殊的欧洲字符,如下所示:
\n\n\xc3\x9c, \xc3\x9f. \xc3\xa4, \xc3\xb6, \xc3\xbc\nRun Code Online (Sandbox Code Playgroud)\n\nMessageSouce bean 如下(我确保遵循 UTF-8 编码)
\n\n <bean id="messageSource"\n class="org.springframework.context.support.ReloadableResourceBundleMessageSource">\n <property name="basename" value="classpath:/META-INF/i18/messages" />\n <property name="defaultEncoding" value="UTF-8" />\n </bean>\nRun Code Online (Sandbox Code Playgroud)\n\n当我尝试在 Java 代码中检索消息时,我收到垃圾字符。
\n\n如果我使用下面的代码,它有助于识别几个字符,但其余的仍然显示为 ??
\n\n return new String (bundleString.getBytes(), "UTF-8")\nRun Code Online (Sandbox Code Playgroud)\n\n然后我用下面的方法对我的属性文件进行编码,但仍然没有效果
\n\nnative2ascii -encoding utf8 resources.utf8 resources.properties\nRun Code Online (Sandbox Code Playgroud)\n\n我还尝试在 Notepad++ 中手动打开我的属性文件并设置 UTF-8 编码,但没有效果。\n我在这里看到一篇文章,与我的问题完全相同。但该解决方案使用 PropertiesBundle,而我必须仅使用基于 Spring 的解决方案。然而,即使该链接中接受的答案也不适合我,并且给出了垃圾字符。
\n\n请提出任何可能的解决方案。
\n小智 3
我遇到了同样的问题,@sunny_dev的答案对我有用。\n我不明白为什么这个问题还没有答案,所以我正在更新这个问题。
\n\n@sunny_dev回答:
\n\n\n\n\nKarol,我通过在 TextPad 中打开并保存 .properties 文件\n 作为“UTF-8”编码和“Unix”平台解决了问题。我采取了相同的方法,但是在 Notepad++ 中没有得到积极的结果。\xe2\x80\x93 sunny_dev
\n
再次感谢@sunny_dev
\n| 归档时间: |
|
| 查看次数: |
6300 次 |
| 最近记录: |