The javadoc for Scanner.hasNextLine() states:
Returns true if there is another line in the input of this scanner.
This method may block while waiting for input. The scanner does
not advance past any input.
Under what conditions will the method block?
解决方案
It depends on the source that the Scanner gets the input from.
For example, if it's a file, the entire input is available, so hasNextLine() wouldn't block (since it can know with certainty when the end of the file is reached and there's no more input.
On the other hand, if the source is standard input, there can always be more input - the user can always type more input - so hasNextLine() would block until the user types in a new line of input.