文字ストリーム_バッファ_テキストファイルのコピーの練習


バッファからテキストファイルをコピー
import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;



public class BufferCopyDemo {

    public static void main(String[] args) {

        BufferedReader bufr = null;

        BufferedWriter bufw = null;

        

        FileReader fr = null;

        FileWriter fw = null;

        

        try{

            

            fr = new FileReader("CopyText.java");

            fw = new FileWriter("Test.java");

           

            bufr = new BufferedReader(fr);

            bufw = new BufferedWriter(fw);



            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(" ");

            }

        }

    }



}