package com.itheima.day17;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Test05_CopyUTF8ToGBK {
public static void main(String[] args) throws IOException {
/*
* 将a.txt(UTF-8格式)中的内容拷贝到b.txt(GBK)中。
*/
InputStreamReader isr = new InputStreamReader(new FileInputStream("a.txt"),"UTF-8");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("b.txt"));
int ch;
while((ch=isr.read())!=-1){
osw.write(ch);
}
isr.close();
osw.close();
}
}
|
|