import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * ListFile display the content of the file given as the parameter of the method "main".
 * Actual parameter of Main(): the name of the file to be displayed, e.g. {"occident.txt"}
 * 
 * @author: Mark Allen Weiss
 * @in "Data Structures & Problem Solving Using Java", chap 2
 */

public class ListerFichier
{
    public static void main( String [ ] args )
    {
        if( args.length == 0 )
            System.out.println( "No files specified" );
        else
            listFile( args[ 0 ] );
    }

    public static void listFile( String fileName )
    {
        FileReader theFile;
        BufferedReader fileIn = null;
        String oneLine;

        System.out.println( "FILE: " + fileName );
        try
        {
            theFile = new FileReader( fileName );
            fileIn  = new BufferedReader( theFile );
            while( ( oneLine = fileIn.readLine( ) ) != null )
                System.out.println( oneLine );
        }
        catch( IOException e )
          {  System.out.println( e ); }
        finally
        {
            // Close the stream
            try
            {
                if(fileIn != null )
                    fileIn.close( );
            }
            catch( IOException e )
              { }
        }
    }
}
