I am trying to encode the Spanish language for internationalization and use the Java Properties class load method to populate it to pass it to frontend.

I have tried to encode it using UTF-8 but still the accent characters are not coming correctly.

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Properties;

public class Message extends Properties {

    public static void main(String[] args) throws IOException {
        String spanish = "label=Sí";
        Message messages = new Message();
        messages.load(new ByteArrayInputStream(spanish.getBytes(Charset.forName("UTF-8"))));

        System.out.println(messages.get("label"));

    }

}

When i run the above code I am getting the text as "Sí-". How can I retrieve the same text as "Sí"?

1 Answers

1
MS90 On Best Solutions

Try using ISO-8859-1 it gets expected result:

 messages.load(new ByteArrayInputStream(spanish.getBytes(Charset.forName("ISO-8859-1"))));

More about ISO-8859-1 can be obtained from this link: https://en.wikipedia.org/wiki/ISO/IEC_8859-1