Question: 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.

```
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;
        }
    }

```

Sample reg.txt:

```
Allegrettho     Albert          0111-27543
Brio            Britta          0113-45771
Cresendo        Crister         0111-27440

```

How should I edit the scanner-reading so that it ignores a new line at the end of the file?

Answer: 
At the end of your loop, do

```
Scanner.nextLine();

```
A dry and dirty way would be to check before every scanner.next() if there is a next line.

```
if(scanner.hasNextLine())
{
  lastname = scanner.next();
}

```

Or after String lastname:

```
if(!lastname.isEmpty())
{
   //continue here...
}

```