0

I have a message.properties file that contains Hebrew sentences like so:

loadData_fileStructureProblem=מבנה הקובץ אינו תקין
listViewer_notEnoughInformation=טיול זה לא מכיל מספיק מידע

Here is how I try to read from the file (an external function):

 public static String getMessagesValue(Context context, String name, String defaults) {
    Resources resources = context.getResources();

    try {

        InputStream rawResource = resources.openRawResource(R.raw.messages);
        Properties properties = new Properties();
        properties.load(rawResource);
        return properties.getProperty(name);

It looks like it can find the right key-value pair but it returns a gibberish sentence like èéåì æä ìà îëéì îñôé÷ îéãò instead of Hebrew.

What I've tried so far?

I saw that there is default encoding for .properties files in android studio. The default in my program was windows-1255 so I've changed it to UTF-8 in Setting > Editor > File encodings but it didn't help. It's only changed the value to be like so מבנה הקובץ ×ינו תקין.

When I try is with English sentences as values it has no problem.

Barlo
  • 86
  • 6
  • Does this answer your question? [Reading from property file containing utf 8 character](https://stackoverflow.com/questions/30755014/reading-from-property-file-containing-utf-8-character). If not make sure the file is actually encoded correctly now that you've change the encoding setting, try opening it from another editor. – Nicolas Apr 12 '20 at 19:55
  • Thank you very much, it works. just surrounding it with new InputStreamReader(input, Charset.forName("UTF-8")) – Barlo Apr 12 '20 at 20:01
  • The accepted answer doesn't really explain it, but the problem is that `Properties.load` assumes by default that the encoding of your file is the ISO 8859-1 encoding (a subset of windows-1252), while yours was UTF-8. There's really no way of automatically "detecting" an encoding, so you have to specify it explicitly. – Nicolas Apr 12 '20 at 20:05

0 Answers0