Assignment #127 and Displaying a File
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Displaying a File
/// File Name: DisplayingAFile.java
/// Date Finished: 06/01/2016/
import java.util.Scanner;
import java.io.File;
public class DisplayingAFile {
public static void main(String[] args) throws Exception{
Scanner kb = new Scanner(System.in);
String fn;
System.out.println("What file would you like to scan? ");
fn = kb.next();
Scanner reader = new Scanner(new File(fn));
while (reader.hasNext()) {
String l = reader.nextLine();
System.out.println(l);
}
}
}
Picture of the output