Assignment #127
Code
/// Name: Kabir Virk
/// Period: 6
/// Program Name: Displaying a File
/// File Name: DisplayingAFile.java
/// Date Finished: 6/1/2016
import java.io.File;
import java.util.Scanner;
public class DisplayingAFile {
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