说明
当 .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);
}
}
}