5

I am using Spring ResourceBundle to retrieve message bundle from my .properties file. It constains special european characters like so:

Ü, ß. ä, ö, ü

MessageSouce bean is as below (I am making sure UTF-8 encoding is followed)

    <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>

When I try to retrieve the message in my Java code I am getting Junk characters.

If I use below code, it helps to recognize few characters, but rest are still showing as ??

 return new String (bundleString.getBytes(), "UTF-8")

Then I used below to encode my properties file, but still no effect

native2ascii -encoding utf8 resources.utf8 resources.properties

I also tried to manually open my properties file in Notepad++ and set UTF-8 encode, but no effect. I see a post here, having exact same problem as mine. But the solution uses PropertiesBundle, whereas I have to use Spring based solution only. However even the accepted answer in that link is not working for me, and giving junk characters.

Please suggest any possible solution.

Community
  • 1
  • 1
sunny_dev
  • 765
  • 3
  • 15
  • 34
  • Please post some examples from the file, both before and after `native2ascii`. Please also provide a partial hexdump of the file. – Karol S Oct 12 '14 at 22:02
  • 2
    Karol, I solved the problem by opening and saving the .properties file in TextPad as "UTF-8" encoding and "Unix" platform. I had taken that same approach, however in Notepad++ without the positive outcome earlier. – sunny_dev Oct 14 '14 at 05:31

1 Answers1

3

I was having the same issue and @sunny_dev's answer worked for me. I don't understand why there is not answer for this question yet so I'm updating the question.

@sunny_dev answer:

Karol, I solved the problem by opening and saving the .properties file in TextPad as "UTF-8" encoding and "Unix" platform. I had taken that same approach, however in Notepad++ without the positive outcome earlier. – sunny_dev

Thanks again to @sunny_dev

DiligentKarma
  • 5,198
  • 1
  • 30
  • 33
lauer
  • 167
  • 10
  • For those who have Notepad++ , the option of "Convert to UTF-8 Without BOM" or "Encode in UTF-8 without BOM" under "Encoding" fixed it for me – ameenhere Oct 24 '17 at 08:16