//http://www.cs.wisc.edu/~cs302/io/JavaIO.html

import java.io.*;

public class FileInputDemo
{
	// Create a single shared BufferedReader for keyboard input
	private static BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );
		
	public static void main (String [] args) throws IOException
	{
		System.out.print( "Enter the filename: " );   // Prompt the user for a file name
		String fileName = stdin.readLine();           // get a file name from the user
		
		File file = new File( fileName ); // create a File object
		
		if ( file.exists() )	// check that the file exists
    	{						// before trying to create a
								// BufferedReader

			// Create a BufferedReader from the file
			BufferedReader inFile = new BufferedReader( new FileReader( file ) );
			
			// Compare the results of calling the readLine method to null
			// to determine if you are at the end of the file.
			String line = inFile.readLine();
			while ( line != null )
			{
				System.out.println( line );	// output to the console
				line = inFile.readLine();	// read another line from the file
			}
			
			// Close the buffered reader input stream attached to the file
			inFile.close();
		}
	}
}
