1

I'm trying to read Hebrew values from a .properties file and I get gibberish. I've tried a couple of ways, including changing the file's encoding (Cp1255, ISO-8859-8, UTF-8), adding a -file.encoding to the arguments and nothing helped.

This issue was raised during our migration to Weblogic from IAS (OC4J container), I noticed the javascript messages (which are read from a .properties file) appear as ???? ???, which does not happen on the OC4J. However, this only applies to data read from .properties files, everything else is shown fine.

I've been googling for a couple of days now and I haven't been able to come up with a solution.

EDIT: What I tried at home

ResourceBundle rb = ResourceBundle.getBundle("test");
System.out.println(rb.getString("test"));

This is what test.properties looks like:

test שלום

Output is: ùìåí

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Bennyz
  • 623
  • 2
  • 18
  • 36
  • We need to see the pieces of what's broken. Where's the code that reads the files? What's the .properties file look like? – Foggzie Dec 27 '12 at 18:28
  • it's nothing too special: the properties file would look like this: someKey שלום And I retrieve the value using ResourceBundle.getString("someKey") (This is what I used on my computer at home and this also generates gibberish) – Bennyz Dec 27 '12 at 18:31
  • 1
    That information should be placed in your question or no one will be able to help. – Foggzie Dec 27 '12 at 18:33

2 Answers2

5

Since you have an instance of ResourceBundle and you can get the ISO-8859-1 encoded String with:

String strISO = rb.getString("test");

You can then convert this to UTF-8 and print it by using:

System.out.println(new String(strISO.getBytes("ISO-8859-1"), "UTF-8"));
Foggzie
  • 9,691
  • 1
  • 31
  • 48
  • Nice trick! Good to have that in the back pocket if you can't modify the bundle itself. – Alex Dec 27 '12 at 18:51
4

Files for ResourceBundle should be in ISO 8859-1 encoding or in \uXXXX format, just as for Properties. See more at How to use UTF-8 in resource properties with ResourceBundle

Community
  • 1
  • 1
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275