FileReader是使用默认码表读取文件, 如果需要使用指定码表读取, 那么可以使用InputStreamReader(字节流,编码表)
FileWriter是使用默认码表写出文件, 如果需要使用指定码表写出, 那么可以使用OutputStreamWriter(字节流,编码表)
package com.fenqing.stream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class demo7_transIO {
public static void main(String[] args) throws IOException {
// simple();
InputStreamReader isr=new InputStreamReader(new FileInputStream("utf-8.txt"),"utf-8");
OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("gbk.txt"),"gbk");
int c;
while((c=isr.read())!=-1){
osw.write(c);
}
isr.close();
osw.close();
}
public static void simple() throws FileNotFoundException, IOException {
FileReader fr=new FileReader("utf-8.txt");
FileWriter fw=new FileWriter("gbk.txt");
int b;
while((b=fr.read())!=-1){
fw.write(b);
}
fr.close();
fw.close();
}
}