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


Using File Objects with Stream Constructors

Some constructors for IO streams that connect to disk files use a File object argument. (Previously, examples used constructors with String arguments). Here is a list of them:

FileInputStream(File file) throws IOException

FileOutputStream(File file) throws IOException

FileReader(File file) throws FileNotFoundException
FileWriter(File file) throws FileNotFoundException

Here is some more of the file copy program, now with blanks to fill in the constructors:

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

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

    . . . .

      instr = 
        new DataInputStream(
          new BufferedInputStream(
            new FileInputStream(  )));

      outstr = 
        new DataOutputStream(
          new BufferedOutputStream(
            new FileOutputStream(   )));
    . . . .


Cut and paste from the following phrases:



Fill in the blanks.