Reading Data from a File

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.

7. Text File Copy Program


Answer:

Yes.

Text File Copy Program

copyImage

The next example program copies a source text file to a destination text file. An already existing file with the same name as the destination file will be destroyed. The names of the source and destination come from the command line. It looks like this:

java CopyMaker original to copy

The illustration shows this working in a command prompt window. Notice how the original file and the copy have the same number of bytes.

Most operating systems come with a user interface that includes a file copy command. The order of the source file and the destination file differs between operating systems. Getting them backwards might be disastrous! Our program requires the word "to" in the command line to ensure that the user knows the correct order.

The program will use a FileReader and a BufferedReader for input and a FileWriter and a BufferedWriter for output.

Question 7:

Can this copy program be used to copy a Microsoft Word document?