自学笔记:
使用String result = new String(str.getBytes("GBK"), "UTF-8");
是将原来为utf-8的字符串,不小心按照gbk格式存放了,而且文件的格式为utf-8,这种情况能解决乱码。
如果文件的格式为gbk,上面的代码无法解决。需要使用
FileOutputStream fos = new FileOutputStream(path); Writer out = new OutputStreamWriter(fos, "UTF-8"); out.write(content); out.close(); fos.close();