java读取properties中文乱码

##

1 确认properties文件的编码是utf-8

2 采用流的方式读取文件,设置编码为utf-8

    static Properties props;
    
    static {
        InputStreamReader isr = null;
        try {
            isr = new InputStreamReader(TitaErrCodeConfig.class.getClassLoader().getResourceAsStream("config/xxx.properties"),"utf-8");
            props = new Properties();
            props.load(isr);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("load config titaErrCode.properties error " + e.getMessage());
        }
    }

猜你喜欢

转载自www.cnblogs.com/moris5013/p/10518392.html