title: Java : How to use scanner.hasNextLine without Ctrl+Z in a console program
body: <p>Say I have the below code</p>
  
  <pre><code>Scanner scanner = new Scanner(System.in);
  while (scanner.hasNextLine()) {
       line = scanner.nextLine();
       //do something
      }
  </code></pre>
  
  <p>And my input in the console is goes like this.</p>
  
  <pre><code>Wayne Rooney
  Luis Nani
  Shinji Kagawa
  </code></pre>
  
  <p>I want to read this line by line.</p>
  
  <p>But the problem is the method hasNextLine blocks waiting for the input after the third line as the input from the keyboard (System.in) never reaches EOF.</p>
  
  <p>Now, how do I reach EOF just by pressing enter key? because I don't want to tell the user to press the Ctrl+z to run my program. </p>
  
  <p>How is it generally done? Any thoughts?</p>
  
  <p>I am looking for a solution from the Java side and not any commands on the console.</p>
  
  <p>Thanks in advance</p>