File I/O Part 1 #127 (SHIA LABEOUF!)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name: Display a File
/// File Name:DaF.java
/// Date Finished: 5/28/2016

    
    import java.io.File;
    import java.util.Scanner;
    
    public class DaF
    {
        public static void main(String[] args) throws Exception
        {
            Scanner keyboard = new Scanner(System.in);
            
            String answer;
            
            System.out.println();
            System.out.print( "Which file would you like to open? " );
            answer = keyboard.next();
            System.out.println();
            
            Scanner fileIn = new Scanner(new File(answer));
            
            while (fileIn.hasNext())
            {
                String x = fileIn.nextLine();
                System.out.println(x);
            }
            
            fileIn.close();
        }
    } 





    

Picture(s) of the output

Assignment 7

Back to Homepage