Advertisement
fosterbl

NameRunner.java

Dec 3rd, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. //Necessary imports
  2. import java.util.Scanner;//Allows us to use the Scanner class
  3. import java.io.File;//Allows us to use the File class to create and Scan a File
  4. import java.io.FileNotFoundException;//It is possible the File class gives an error that we need to handle
  5.  
  6. public class NameRunner{
  7.    //Don't worry about the throws part, not on the AP test, necessary to handle aforementioned error
  8.    public static void main(String[] args) throws FileNotFoundException{
  9.      
  10.       //Create a file using the directory and file you downloaded, YOUR directory may be different
  11.       File text = new File("C:\\Users\\FOSTERBL\\Downloads\\yob2008.txt");
  12.       //Make the Scanner read the file
  13.       Scanner fileScanner = new Scanner(text);
  14.      
  15.       //Keep going while the file has another line
  16.       while( fileScanner.hasNextLine() ){
  17.          //Print each line using the default delimiter, which is whitespace (new line)
  18.          System.out.println( fileScanner.nextLine() );
  19.       }
  20.    }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement