#6: File objects represent files

The following program returns various information about a file that can't exist on any platform!

import java.io.*;


public class FileInfo {

  public static void main(String[] args) {
  
    File f = new File("-What/a\bad file name?!" + '\u0000'); 
    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.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.");
    } 
  
  }

}

Previous | Next | Top | Cafe au Lait |Cafe con Leche

Copyright 1999, 2002 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 30, 2002