码迷,mamicode.com
首页 > 编程语言 > 详细

java的IO流,实现中文字符的复制

时间:2019-06-20 23:58:55      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:puts   div   io流   NPU   work   edr   fileinput   复制   write   

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流,实现中文字符的复制

标签:puts   div   io流   NPU   work   edr   fileinput   复制   write   

原文地址:https://www.cnblogs.com/ouyangbo/p/11062083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!