Advertisement
Guest User

Calling System to read a file (error)

a guest
Mar 19th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1.  
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5.  
  6. public class Question4
  7. {
  8.     public static void main(String[] args) throws IOException
  9.     {
  10.         Scanner keyboard = new Scanner(System.in);
  11.         System.out.println("Enter filename");
  12.         String filename = keyboard.nextLine();
  13.  
  14.         File test1 = new File("test1.txt");
  15.         Scanner inputFile = new Scanner(test1);
  16.  
  17.         while (inputFile.hasNext())
  18.         {
  19.             String file = inputFile.nextLine();
  20.             System.out.println(file);
  21.         }
  22.         inputFile.close();
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement