Skip to main content

Java: Loading Resource Bundle File with UTF-8

No replies
Joined: 2007-03-09

I have prepared both Eclipse (JSP Files) and GlassFish to run all my files in charset UTF-8. Then i got my resource bundle files(property files) to use UTF-8 encoding. Everything looks fine in my text editor. Then when i upload these pages every character retrieved from my resource bundles look garbled. This is because Java loads property files using ISO 8859-1 character encoding. This is a problem from Sun i have read on the internet!
Note: that in JDK 1.6, you can use PropertyResourceBundle constructor to take a Reader which uses UTF-8 encoding.

please have a look at these links for more info:
Note: PropertyResourceBundle can be constructed either from an InputStream or a Reader, which represents a property file. Constructing a PropertyResourceBundle instance from an InputStream requires that the input stream be encoded in ISO-8859-1. In that case, characters that cannot be represented in ISO-8859-1 encoding must be represented by Unicode Escapes, whereas the other constructor which takes a Reader does not have that limitation.

What i have read and understand is that the real solution to the problem is: Get the fmt lib to use a Reader instead of an InputStream. Alternativly if it works get a ResourceBundle instead of creating one that is wrong all the time? I have to create my own ResourceBundle instead of using my own fmt lib wich i cannot trust in a way any more. Is this right or am i comletly wrong?

My WebTexts files, en, sv and ry are my resource property bundles. To be able to read them i will use resource property bundle reader. Fmt lib gives me this but it seems that it inciates this in an InputStream (wich is looked to iso-8859-1) instead of a reader who can read UTF-8 without no problem. So can i get my fmt lib to change this or not, anybody have an idea about this???