loader image
Skip to main content
If you continue browsing this website, you agree to our policies:
x
Completion requirements

This chapter discusses Java's FileReader and BufferedReader classes in detail. FileReader and BufferedReader classes are used together when reading data from an external file. The use of the BufferedReader class allows data to be buffered as it is read from a file before manipulating it. The readLine() method of the BufferedReader class reads a line of text from a character-oriented input stream, and puts it into a new String object.

12. CopyFile Method


Answer:

Probably this would be OK.

CopyFile Method

The copyFiles() method finally gets down to copying the file. The loop that does the work is just a few statements long!

class CopyMaker
{
   String sourceName, destName;
   BufferedReader source;
   BufferedWriter dest;
   String line;

   private void copyFiles()
   {
     try
     {      
       line = source. ;
       
       // while not End-of-File
       while (  )
       {
         dest. (line);
         line = source. ;
       }
     }
     catch ( IOException iox )
     {
       System.out.println("Problem reading or writing" );
     }
   }
}

Question 12:

Click in the blanks.