Java 读取properties配置文件中文乱码

说明

当 .properties 文件包含中文时,需要将字节流转字符流,并使用 UTF-8 编码,否则会出现乱码:

private void readProperties() throws IOException {

    Properties properties = new Properties();
    try(InputStream fis = new FileInputStream("config.properties")) {
        // 字节流转字符流
        try(InputStreamReader isr = new InputStreamReader(fis,"UTF-8")){
            properties.load(isr);
        }
    }

}

原文出处:/show_1GWBqcd5OHo.html