解决在读取properties文件中出现中文报错问题

// 读取properties中的参数
        Properties properties = new Properties();
        // 读取properties文件  使用InputStreamReader来解决中文报错问题
        InputStreamReader inputStreamReader = null;
//        InputStream inputStream = Main.class.getResourceAsStream("/file.properties");
        // 需要遍历的路径  --在properties文件中
        String path = "";
        try {
            inputStreamReader =  new InputStreamReader(Main2.class.getResourceAsStream("/file.properties"),"UTF-8");
            properties.load(inputStreamReader);
            // 读取到properties中的参数 赋值给path
            path = properties.getProperty("path");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            // 释放inputStream
            try {
                inputStreamReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

  

猜你喜欢

转载自www.cnblogs.com/CanBlog/p/11370335.html