Assignemnt #127 DisplayingAFile

Code

    /// Name: Drew Boxold
    /// Period 5
    /// Program Name: DisplayingAFile
    /// File Name: DisplayingAFile.java
    /// Date Finished: 6/2/2016
    
import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class DisplayingAFile
{
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        
        String fileName;
        String x;
        
        System.out.println("\nHere are a list of files you can open:\n\n- address.txt\n- some-words.txt\n- receipt.txt\n- 3nums.txt\n- score.txt\n");
        
        System.out.print("Which file would you like to open? ");
        fileName = keyboard.nextLine();
        System.out.println();
        
        try{
            Scanner fileIn = new Scanner(new File(fileName));
            
            while (fileIn.hasNextLine())
            {
                x = fileIn.nextLine();
                System.out.println(x);
            }
            
            fileIn.close();
            System.out.println();
        }
        
        catch (IOException e){
            System.out.println("Error");
        }
        System.out.println("\nDone");
    }
}
    

Picture of the output

Assignment 41