// This reads a file, one line at a time // For each line, it uses a Scanner to break it into tokens import java.io.*; import java.util.*; public class ReadFile2 { public static void main(String[] args) throws FileNotFoundException { // This scanner scans the file Scanner scanFile = new Scanner(new File("data2.txt")); while ( scanFile.hasNextLine() ) { // Get the next line in the file String s = scanFile.nextLine(); System.out.println("line: " + s); // This scanner scans the string with one line Scanner scanLine = new Scanner(s); // Get/print the tokens in the line as strings while ( scanLine.hasNext() ) { String t = scanLine.next(); System.out.println(t); } } } }