我正在使用Spring ResourceBundle從我的.properties文件中檢索消息包。它constains特殊歐洲字符,像這樣:特殊字符的Spring資源包的UTF-8編碼問題
Ü, ß. ä, ö, ü
MessageSouce bean是如下(我確保UTF-8編碼之後)
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:/META-INF/i18/messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
當我嘗試在我的Java代碼來檢索消息我正在接收垃圾字符。
如果我使用下面的代碼,它有助於識別幾個字符,但其餘的仍然顯示爲?
return new String (bundleString.getBytes(), "UTF-8")
然後我下面用於編碼我的屬性文件,但仍然沒有效果
native2ascii -encoding utf8 resources.utf8 resources.properties
我也試圖手動打開我的屬性在記事本++文件,然後設置UTF-8編碼,但沒有效果。 我看到帖子here,與我的問題完全相同。但是解決方案使用了PropertiesBundle,而我只能使用基於Spring的解決方案。然而,即使在該環節中接受的答案也不適合我,並給予垃圾角色。
請建議任何可能的解決方案。
請之前和之後'native2ascii'從文件發佈一些例子。還請提供文件的部分hexdump。 – 2014-10-12 22:02:26
Karol,我通過在TextPad中打開並保存.properties文件作爲「UTF-8」編碼和「Unix」平臺解決了這個問題。我採取了同樣的方法,但是在Notepad ++之前沒有獲得積極的結果。 – 2014-10-14 05:31:59