It may not be causing a problem right now but have you tried using hasNext() instead of hasNextLine() as the latter may return true even if there is nothing in the next line.

As for your actual...