Assignemnt #127 Displaying a File
Code
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.print("Open which file: ");
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