java的IO流,实现中文字符的复制
2020-12-13 02:57
标签:puts div io流 NPU work edr fileinput 复制 write FileReader和FileWriter不支持中文 java的IO流,实现中文字符的复制 标签:puts div io流 NPU work edr fileinput 复制 write 原文地址:https://www.cnblogs.com/ouyangbo/p/11062083.htmlpackage oyb;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Test {
public static void main(String[] args) throws IOException{
int b = 0;
FileInputStream in = new FileInputStream("D:\\workspace\\test.txt");
InputStreamReader isr = new InputStreamReader(in,"GB2312");
BufferedReader br = new BufferedReader(isr);
FileOutputStream os = new FileOutputStream("D:\\workspace\\test2.txt");
OutputStreamWriter osw = new OutputStreamWriter(os,"GB2312");
BufferedWriter bw = new BufferedWriter(osw);
while((b = br.read()) != -1) {
// System.out.print((char) b);
bw.write(b);
}
bw.close();
br.close();
}
}