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