[英]Spanish language encoding issue with Java Properties class load method
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.我正在尝试对西班牙语进行国际化编码,并使用 Java Properties 类加载方法来填充它以将其传递给前端。
I have tried to encode it using UTF-8 but still the accent characters are not coming correctly.我尝试使用 UTF-8 对其进行编码,但仍然无法正确显示重音字符。
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Ã-".当我运行上面的代码时,我得到的文本为“SÃ-”。 How can I retrieve the same text as "Sí"?
如何检索与“Sí”相同的文本?
Try using ISO-8859-1 it gets expected result:尝试使用 ISO-8859-1 会得到预期的结果:
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更多关于 ISO-8859-1 的信息可以从这个链接获得: https : //en.wikipedia.org/wiki/ISO/IEC_8859-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.