Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1.  
  2. import java.nio.file.Paths;
  3. import java.util.Scanner;
  4.  
  5. public class PrintingAFile {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         try ( Scanner scanner = new Scanner(Paths.get("data.txt"))) {
  10.  
  11.             // we read the file until all lines have been read
  12.             while (scanner.hasNextLine()) {
  13.                 // we read one line
  14.                 String row = scanner.nextLine();
  15.                 // we print the line that we read
  16.                 System.out.println("Whats goingon ?");
  17.                 System.out.println(row);
  18.             }
  19.         } catch (Exception e) {
  20.             System.out.println("Error: " + e.getMessage());
  21.         }
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement