/********************************************************************** * Author: Eric Heim * Date Created: 7/14/2011 * Course: CS0007 * Description: Shows the use of the hasNext method in the Scanner * class to detect for the end of a file. **********************************************************************/ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class HasNext { public static void main(String[] args) throws FileNotFoundException { File myFile = new File("myFile.txt"); Scanner inputFile = new Scanner(myFile); while(inputFile.hasNext()) { System.out.println(inputFile.nextLine()); } inputFile.close(); } }