import java.io.*;
public class FileTestImproved {
  public static void main(String[] args) 
                     throws Exception {
    File testFile = new File("test.txt");
    if (testFile.exists()) {
      System.out.println("Checking " + testFile.getName()
                         + (testFile.isFile() ? 
                           " is a file" : " is not a file"));
  }
    File thisDir = new File(".");
    if (thisDir.exists()) {
      System.out.println("Directory " + thisDir.getAbsolutePath());
      if (thisDir.isDirectory()) {
        String[] dirListing = thisDir.list();
        if (dirListing != null) {
          System.out.println("  first file is " + dirListing[0]);
        }
        else {
          System.out.println("  has no files");
        }
      }
      else {
         System.out.println("  is not a directory");
      }
    }
    else {
      System.out.println("File or directory doesn't exist");
    }
  }
}