java读取properties文件,中文乱码处理


查看properties乱码的问题。通过修改eclipse配置可以解决:(eclipse打开properties配置文件中文显示字符的编码

java读取properties文件,中文乱码处理

Java读取properties文件中文乱码问题的解决  

无论系统的默认编码是什么,在读取properties文件时使用的iso8859-1编码。

解决方法是:

读取的字符用字符编码:

        InputStream resource = TestOut.class.getClassLoader().getResourceAsStream("db.properties");
        Properties properties2 = new Properties(); properties2.load(resource); String property = properties2.getProperty("java"); System.out.println("----" + new String(property.getBytes("iso-8859-1")));

properties文件:

java=java项目

 

以下是API说明部分: 

When saving properties to a stream or loading them from a stream, the ISO 8859-1 character encoding is used. For characters that cannot be directly represented in this encoding, Unicode escapes are used; however, only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.

下面是源码:BufferedReader in = new BufferedReader(new InputStreamReader(inStream,"8859_1"));


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM