Assignment #127 and Displaying a File
Code
/// Name: Brendan Baird
/// Period: 6
/// Program Name: Displaying a File
/// File Name: DisplayFile.java
/// Date Finished: 2/29/2016
import java.io.File;
import java.util.Scanner;
public class DisplayFile {
public static void main(String[] args) throws Exception {
String file;
Scanner k = new Scanner(System.in);
System.out.print("Open which file: ");
file = k.next();
Scanner fileReader = new Scanner(new File(file));
while(fileReader.hasNext()) {
String line = fileReader.nextLine();
System.out.println(line);
}
fileReader.close();
}
}
Picture of the output