Advertisement
Guest User

q2

a guest
Jan 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.63 KB | None | 0 0
  1. package harr4603_lab02;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.Scanner;
  6.  
  7. /**
  8.  * Reads source file
  9.  * @author Jordan Harris
  10.  * @version 1.0
  11.  *
  12.  */
  13. public class readSource {
  14.  
  15.     public static void main(String[] args) throws FileNotFoundException
  16.     {
  17.         File file = new File("src/harr4603_lab02/ScannerTest.java");
  18.         Scanner source = new Scanner(file);
  19.         int lines = 0;
  20.         while(source.hasNextLine())
  21.         {
  22.             System.out.println(source.nextLine());
  23.             lines++;
  24.         }
  25.         System.out.println("This source file has: " + lines + " lines.");
  26.  
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement