Java(117):读取properties配置文件中文乱码问题解决

1、Edit展示properties后缀文件时乱码

2、读取properties配置文件中文乱码问题解决

2.1、文件存储为UTF-8格式

2.2、读取时设置为UTF-8格式

String enconding = "UTF-8";  
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), enconding));

    public static Properties getProperty() throws Exception{
        //从配置文件中获取
        Properties properties = new Properties();
        try {
            //当前工作目录
            String path = System.getProperty("user.dir");
            String filePath = path + "/jdbc.properties";
            String enconding = "UTF-8";    //不管windows还是linux都是UTF-8
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), enconding));
            properties.load(br);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return properties;

    }

猜你喜欢

转载自blog.csdn.net/fen_fen/article/details/131537610