When scanning a file eventually the scanner gets to the end of stream marker and so it knows there's no more data to scan and so hasNext() returns false. However, when scanning from the command line...