class hello {
public static void main(String[] args) throws IOException {
BufferedReader isp = new BufferedReader(new FileReader("xxx.txt"));
//OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("yyy.txt"), "utf-8");//利用UTF-8编码写字符
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("yyy.txt"), "gbk");//利用GBK编码写字符
int a;
while((a = isp.read()) != -1) {
osw.write(a);
}
isp.close();
osw.close();
}
先将yyy.txt的编码改成GBK
如果使用UTF-8编码写字符
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("yyy.txt"), "utf-8");
运行结果:
改成GBK编码写字符:
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("yyy.txt"), "gbk");