Chapter 20: Files and Streams

Page 476: Opening a FileOutputStream to a file that doesn't exist will create the file. Delete the paragraph that claims otherwise.

In examples 20.1 through 20.5 you also need to import java.io.IOException. Add the following line to the top of each of those examples.

import java.io.IOException;

On page 485, the quote marks in the code fragment at the bottom of the page should be straight, not curly.

In program 20.6 on pages 493-495, the try-catch block is unnecessary and may be removed. The corrected program is

import java.io.File;
import java.io.IOException;


public class FileInfo {


  public static void main(String[] args) {
  
    for (int i = 0; i < args.length; i++) {
      File f = new File(args[i]);
      if (f.exists()) {
        System.out.println("getName: " + f.getName());
        System.out.println("getPath: " + f.getPath());
        System.out.println("getAbsolutePath: " + 
          f.getAbsolutePath());
        System.out.println("getParent: " + f.getParent());
        if (f.canWrite()) System.out.println(f.getName() + 
          " is writable.");
        if (f.canRead()) System.out.println(f.getName() + 
          " is readable.");
        if (f.isFile()) {
           System.out.println(f.getName() + " is a file.");
        }
        else if (f.isDirectory()) {
          System.out.println(f.getName() + " is a directory.");
        }
        else {
          System.out.println("What is this?");
        }
        if (f.isAbsolute()) {
          System.out.println(f.getName() + 
            " is an absolute path.");
        }
        else {
          System.out.println(f.getName() + 
            " is not an absolute path.");
        }
        System.out.println("Last Modified" + 
          f.lastModified());
        System.out.println(f.getName() + " is " + 
          f.length() + " bytes.");
        System.out.println(f.getName() + " is " + 
          f.length() + " bytes.");
      }  
      else {
         System.out.println("I'm sorry. I can't find the file "
           + args[i]);
      }
      
    }
  
  }

}

Corrections to Other Chapters
[ Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]
Copyright 1996-8 Elliotte Rusty Harold
elharo@sunsite.unc.edu
Last Modified July 12, 1998