Java国际化开发时不明白为什么需要将本身就是utf-8格式的含中文的properties文件使用native2ascii工具转Unicode?
message_zh_CN.properties
1 | name=中国 |
1 | public class HelloWorld { |
Java中properties文件都是使用InputStream inStream 字节流加载的。而InputStream字节流默认使用ISO 8859-1字符编码集。所以需要使用native2ascii工具将utf-8文件进行转码操作。
这是 Java 的一个缺陷,因为当初还没有 Unicode,所以才会这样,从 Java 9 开始,properties 文件已经改为缺省 utf8 编码了。
转载 https://segmentfault.com/q/1010000013011825
参考
https://docs.oracle.com/javase/9/intl/internationalization-enhancements-jdk-9