首页 > 其他 > 详细

字符输入输出流

时间:2017-04-25 20:31:58      阅读:239      评论:0      收藏:0      [点我收藏+]
package com.sxt.copy2;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

/*
 * 字符输入输出流
 * Reader
 * Writer
 */
public class TestCopy {
    public static void main(String[] args) {
        Reader reader = null;
        Writer writer = null;
        try {
            reader = new FileReader("F:\\01_面向对象设计思想_重要_1.avi");
            writer = new FileWriter("G:\\CopyDest.avi");
            char[] cbuf = new char[1024];
            //第一步:读文件到程序
            int len = 0;
            while((len = reader.read(cbuf))!= -1){
                System.out.println(len);
                writer.write(cbuf, 0, len);//第二部:从程序写到文件中
            }
            System.out.println("Copy执行完成!");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(reader != null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(writer != null){
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        
    }
}

 

字符输入输出流

原文:http://www.cnblogs.com/qingfengzhuimeng/p/6764098.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!