A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 1066715808 中级黑马   /  2016-1-11 23:53  /  1972 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*
通过缓冲区复制一个.java文件。

*/
import java.io.*;

class  CopyTextByBuf
{
        public static void main(String[] args)
        {
                BufferedReader bufr = null;
                BufferedWriter bufw = null;

                try
                {
                        bufr = new BufferedReader(new FileReader("Test.java"));
                        bufw = new BufferedWriter(new FileWriter("Test_Copy.txt"));

                        String line = null;

                        while((line=bufr.readLine())!=null)
                        {
                                bufw.write(line);
                                bufw.newLine();
                                bufw.flush();

                        }
                }
                catch (IOException e)
                {
                        throw new RuntimeException("读写失败");
                }
                finally
                {
                        try
                        {
                                if(bufr!=null)
                                        bufr.close();
                        }
                        catch (IOException e)
                        {
                                throw new RuntimeException("读取关闭失败");
                        }
                        try
                        {
                                if(bufw!=null)
                                        bufw.close();
                        }
                        catch (IOException e)
                        {
                                throw new RuntimeException("写入关闭失败");
                        }
                }
        }
}
//此方法主要通过缓冲技术提高文件读写的速度

2 个回复

倒序浏览
楼主写的真好
回复 使用道具 举报
但是让我去说
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马