Corrections to Chapter 4 of Java I/O, File Streams

p. 49: In Example 4-1:

System.err.println("Usage: java FileCopier file1 file2 ...");

should be

System.err.println("Usage: java FileTyper file1 file2 ...");

p. 52: Here's a slightly revised version of Example 4-2 that avoids some misconceptions a few people reported:

import java.io.*;
import com.macfaq.io.*;


public class FileCopier {

  public static void main(String[] args) {

    if (args.length != 2) {
      System.err.println("Usage: java FileCopier infile outfile");
			return;
    }
    try {
      copy(args[0], args[1]);
    }
    catch (IOException e) {
      System.err.println(e);
    }

  }

  public static void copy(String inFile, String outFile) 
   throws IOException {

    FileInputStream fin = null;
    FileOutputStream fout = null;
    
    try {
      fin  = new FileInputStream(inFile);
      fout = new FileOutputStream(outFile);
      StreamCopier.copy(fin, fout);
    }
    finally {
      try {
        if (fin != null) fin.close();
      }
      catch (IOException e) {}
      try {
        if (fout != null) fout.close();
       }
      catch (IOException e) {}
    }

  }

}
p. 54: In Example 4-3
    if (args.length < 1) {
      System.err.println("Usage: java FileDumper [-ahd] file1 file2...");
    }
should be

    if (args.length < 1) {
      System.err.println("Usage: java FileDumper [-ahd] file1 file2...");
      return;
    }

[ Java I/O Corrections | Java I/O Home Page | Table of Contents | Examples | Order from Amazon ] ]

Copyright 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified May 21, 1999