• 考试第四题


    package test04;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.Reader;
    import java.io.Writer;
    
    public class Demo {
        //在C盘下创建一个文件,名称为javabigdata,在此文件夹下创建一个a.txt的文件
        //,并写入如下内容:I love china,I love beiijng,the Beijing
        //is the capatial of China.,
        //然后将a.txt复制到此文件夹下为b.txt
    
        //1、地址   2、读取 Read FileRead   BUfferRead 输出 Write FileOut  BufferWriter
        
        
        public static void main(String[] args) {
            
            
            Reader re = null;
            BufferedReader br = null;
            Writer wi = null;
            BufferedWriter bw = null;
            
            try {
                re = new FileReader("C:/javabigdata/a.txt");
                br = new BufferedReader(re);
                try {
                    wi = new FileWriter("C:/javabigdata/b.txt");
                    bw = new BufferedWriter(wi);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                String line = "";
                try {
                    while((line=br.readLine())!=null) {
                        
                        bw.write(line);
                        System.out.println("复制成功");
                        bw.flush();
                        
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally {
                
                try {
                    bw.close();
                    wi.close();
                    br.close();
                    re.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
            
        }
        
        
        
        
    }

  • 相关阅读:
    MySQL事务
    MySQL索引
    MySQL基础
    设计模式之单例模式
    设计模式之适配器模式
    zookeeper学习记录第二篇-----安装、配置、启动
    Scrapy 安装
    shiro
    python 爬虫简介以及使用方法
    linux VMware使用
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11336263.html
Copyright © 2020-2023  润新知