java的IO流,实现中文字符的复制
Posted ouyangbo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java的IO流,实现中文字符的复制相关的知识,希望对你有一定的参考价值。
package 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();
FileReader和FileWriter不支持中文
以上是关于java的IO流,实现中文字符的复制的主要内容,如果未能解决你的问题,请参考以下文章