title: Using Scanner to read from text file
body: <p>I am writing a program that takes a year as user input and returns the super bowl winner for that year (using a text file of a list of super bowl winners). It compiles correctly but when I try to execute the program I get the error:</p>
  
  <p>Exception in thread "main" java.util.NoSuchElementException: No line found
          at java.util.Scanner.nextLine(Scanner.java:1540)
          at Hw5pr4.main(Hw5pr4.java:17)</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Text file:</p>
  
  <pre><code>1967 Green Bay Packers
  1968 Green Bay Packers
  1969 New York Jets
  1970 Kansas City Chiefs
  1971 Baltimore Colts
  1972 Dallas Cowboys
  1973 Miami Dolphins
  1974 Miami Dolphins
  1975 Pittsburgh Steelers
  1976 Pittsburgh Steelers
  1977 Oakland Raiders
  1978 Dallas Cowboys
  1979 Pittsburgh Steelers
  1980 Pittsburgh Steelers
  1981 Oakland Raiders
  1982 San Francisco 49ers
  1983 Washington Redskins
  1984 Los Angeles Raiders
  1985 San Francisco 49ers
  1986 Chicago Bears
  1987 New York Giants
  1988 Washington Redskins
  1989 San Francisco 49ers
  1990 San Francisco 49ers
  1991 New York Giants
  1992 Washington Redskins
  1993 Dallas Cowboys
  1994 Dallas Cowboys
  1995 San Francisco 49ers
  1996 Dallas Cowboys
  1997 Green Bay Packers
  1998 Denver Broncos
  1999 Denver Broncos
  2000 St. Louis Rams
  2001 Baltimore Ravens
  2002 New England Patriots
  2003 Tampa Bay Buccaneers
  2004 New England Patriots
  2005 New England Patriots
  2006 Pittsburgh Steelers
  2007 Indianapolis Colts
  2008 New York Giants
  2009 Pittsburgh Steelers
  2010 New Orleans Saints
  2011 Green Bay Packers
  2012 New York Giants
  2013 Baltimore Ravens
  2014 Seattle Seahawks
  2015 New England Patriots
  </code></pre>
  
  <p>Source code:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Hw5pr4
  {
      public static void main(String[] args) throws IOException{
          File winners = new File("SuperBowlWinners.txt");
          Scanner reader = new Scanner(winners);
          String[][] data = new String[49][2];
  
          int index = 0;
          while(reader.hasNext()){
              int yr = reader.nextInt();
              String year = Integer.toString(yr);
              data[index][0] = year;
              reader.nextLine();
              data[index][1] = reader.nextLine();
              index++;
          }
  
          Scanner keyboard = new Scanner(System.in);
          System.out.println("Enter a year, or to exit, enter STOP");
          String input = keyboard.nextLine();
  
          String winner = "Not found";
          boolean found = false;
          while(input!="STOP"){
              for(int i=0; i&lt;49; i++){
                  if(input.equals(data[i][0])){
                      winner = data[i][1];
                      found = true;
                  }
              }
              System.out.println("Enter a year, or to exit, enter STOP");
              input = keyboard.nextLine();
          }
          if(found)
              System.out.println(winner);
          else
              System.out.println("Error: the year is not in the data.");
      }
  }
  </code></pre>