查看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"));