go to previous page   go to home page   go to next page

Answer:

Absolute.


Improved File Copy Program

import java.io.*;
class CopyBytes
{
  public static void main ( String[] args ) 
  {
    DataInputStream  instr;
    DataOutputStream outstr;

    if ( args.length != 3 || !args[1].toUpperCase().equals("TO") )
    {
      System.out.println("java CopyBytes source to destination");
      return;
    }

    File inFile  = new File( args[0] );
    File outFile = new File(  );

    if ( outFile.  )
    {
      System.out.println( args[2] + " already exists");
      return;
    }

    if (  inFile.  )
    {
      System.out.println( args[0] + " does not exist");
      return;
    }

    .  .  .  .  

  }
}

The exists() method tests if a file exists. Do this when a program is about to create a file and you don't want to destroy a previous file of the same name.

Let us improve the file copy program from the previous chapter so that it tests that: (1) the destination file does not already exist, and that (2) the source file does exist. A start on this program is above.


QUESTION 6:

Fill in the blanks so the program works as described. Cut and paste the following phrases (some phrases may be used more than once):

exists()
args[2]
!

go to previous page   go to home page   go to next page