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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 222222222222 初级黑马   /  2016-6-3 14:46  /  505 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.io.*;
/*
通过缓冲区复制一个.java文件
*/
class Demo2
{
        public static void main(String[] args)
        {
                BufferedReader br=null;
                BufferedWriter bw=null;

                try
                {
                        br=new BufferedReader(new FileReader("demo.txt"));
                        bw=new BufferedWriter(new FileWriter("x.txt"));
                        
                        String line=null;
                        while((line=br.readLine())!=null)
                        {
                                bw.write(line);
                                bw.newLine();
                                bw.flush();
                        }
                }
                catch (IOException e)
                {
                        throw new RuntimeException("读写失败");
                }
                finally
                {
                        
                        try
                        {
                                if(br!=null)
                                br.close();
                        }
                        catch (IOException e)
                        {
                                throw new RuntimeException("读写关闭失败");
                        }
                        
                        try
                        {
                                if(bw!=null)
                                bw.close();
                        }
                        catch (IOException e)
                        {
                                throw new RuntimeException("关闭失败");
                        }
                        

                }
        }
}

2 个回复

倒序浏览
很好!!!!!!!!!!
回复 使用道具 举报
支持多多I支持
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马