Properties文件中文乱码问题

来源:互联网 发布:王者荣耀淘宝代充原理 编辑:程序博客网 时间:2024/05/16 00:59

properties文件的编码格式为UTF-8,但是使用如下代码读取的时候就出现中文乱码问题:

public class PropUtil {    Properties prop = new Properties();    InputStream in = PropUtil.class            .getResourceAsStream("/subject.properties");    try {        prop.load(in);    } catch(Exception e) {    } finally {        try {            if (in != null) {                in.close();            }        } catch (IOException e) {            e.printStackTrace();        }    }}后来发现需要将InpustStream再包装成BufferedReader问题就解决了:

BufferedReader reader = new BufferedReader(new InputStreamReader(in));
“`
然后再调用Properties对象的load()方法,中文乱码的问题就解决了。

0 0
原创粉丝点击