解决IDEA 读取properties配置文件中文乱码问题
方法一查看文件编码类型是不是 utf-8
如果不是 修改为uft-8
然后就设置读取时的编码类型
InputStream resourceAsStream = equalsDemo.class.getClassLoader().getResourceAsStream("test.properties");
Properties pro = new Properties();
pro.load(new InputStreamReader(resourceAsStream,"UTF-8"));
String name = pro.getProperty("name");
System.out.println(name);
输出
方法二 通过 InputStreamReader 转字节流为字符流
InputStream res = ClassLoader.getSystemClassLoader().getResourceAsStream("test.properties");
pro.load(new InputStreamReader(res,"UTF-8"));
本文来自博客园,作者:冰莫莫,转载请注明原文链接:https://www.cnblogs.com/icemomo/p/16156331.html