在写文件时,如下定义bw,写入的中文总是乱码,
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filePath),false), "UTF-8"));
在使用如下方法写入时,仍是乱码:
bw.write(new String(s.getBytes("gbk"),"utf-8"));
最后采用如下方法定义bw,才解决问题:
BufferedWriter bw = new BufferedWriter(new FileWriter(filePath));
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/13747.html