Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Necessary imports
- import java.util.Scanner;//Allows us to use the Scanner class
- import java.io.File;//Allows us to use the File class to create and Scan a File
- import java.io.FileNotFoundException;//It is possible the File class gives an error that we need to handle
- public class NameRunner{
- //Don't worry about the throws part, not on the AP test, necessary to handle aforementioned error
- public static void main(String[] args) throws FileNotFoundException{
- //Create a file using the directory and file you downloaded, YOUR directory may be different
- File text = new File("C:\\Users\\FOSTERBL\\Downloads\\yob2008.txt");
- //Make the Scanner read the file
- Scanner fileScanner = new Scanner(text);
- //Keep going while the file has another line
- while( fileScanner.hasNextLine() ){
- //Print each line using the default delimiter, which is whitespace (new line)
- System.out.println( fileScanner.nextLine() );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement