title: Scanner - Ignore new line at end of file
body: <p>I need some help with quitting when coming to/ignoring the last new line in the file reg.txt. As of right now I get an error when it reaches the last line, containing nothing.</p>
  
  <pre><code>public String load() {
          list.removeAllElements();
          try {
              Scanner scanner = new Scanner(new File("reg.txt"));
  
              while (scanner.hasNextLine()) {
                  String lastname = scanner.next();
                  String firstname = scanner.next();
                  String number = scanner.next();
                  list.add(new Entry(firstname, lastname, number));
              }
              msg = "The file reg.txt has been opened";
              return msg;
          } catch (NumberFormatException ne) {
              msg = ("Can't find reg.txt");
              return msg;
          } catch (IOException ie) {
              msg = ("Can't find reg.txt");
              return msg;
          }
      }
  </code></pre>
  
  <p>Sample reg.txt:</p>
  
  <pre><code>Allegrettho     Albert          0111-27543
  Brio            Britta          0113-45771
  Cresendo        Crister         0111-27440
  </code></pre>
  
  <p>How should I edit the scanner-reading so that it ignores a new line at the end of the file?</p>