FileReader编码问题

FileReader编码问题

在一次使用FileReader读取文件转换json时,出现了在linux上正常在windows上转换错误的情况

因为FileReader使用的是系统默认字符集去读取

new FileReader(new File(x)).getEncoding() // windows上为GBK

解决方式为:

new InputStreamReader(new FileInputStream(new File(x)), StandardCharsets.UTF_8) // 指定读取字符集
原文地址:https://www.cnblogs.com/xcmelody/p/12245828.html