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

时间:2019-08-17
本文章向大家介绍解决在读取properties文件中出现中文报错问题,主要包括解决在读取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();
            }
        }

  

原文地址:https://www.cnblogs.com/CanBlog/p/11370335.html