// File: DisplayFile.java
// Author: Mike Wade
// Last Modified: 12/2/1999

import java.io.*;

/**
 * This program asks the user to enter the name of a file, and then
 * prints the contents of that file to stdout.  If the file does not
 * exist or is a directory, an error message is displayed
 **/
class DisplayFile {

    public static void main(String [] args) throws IOException {
        BufferedReader stdin = new BufferedReader(
            new InputStreamReader(System.in));
        
        // Prompt for and get the file name
        System.out.print("Enter the name of the file to echo: ");
        String fileName = stdin.readLine();

        File sourceFile = new File(fileName); // Create the file
        
        // If the file does not exist, print out an error message and exit
        if (sourceFile.exists() == false) {
            System.err.println("Echo: " + fileName + ": No such file");
            System.exit(1);
        }

        // If the file is a directory, print out an error message and exit
        if (sourceFile.isDirectory()) {
            System.err.println("Echo: " + fileName + ": Is a directory");
            System.exit(1);
        }
        
        // Create an object to read from the file
        BufferedReader fin = new BufferedReader(new FileReader(sourceFile));

        // Read each line of the file, and print each line to stdout
        while (fin.ready()) {
            System.out.println(fin.readLine());
        }

        fin.close();
    }
}



        
