title: Java console program and CTRL-C
body: <pre><code>import java.util.Scanner;
  
  public class test {
      public static void main(String[] args) {
  
          Runtime.getRuntime().addShutdownHook(new Thread() {
              public void run() {
                  System.out.println("Shutdown.");
              }
          });
  
          String input ="";
          Scanner in = new Scanner(System.in);
  
          while(true) {
              System.out.print("&gt; ");
  //          if (in.hasNext())
                  input = in.nextLine();
  
              if (input.equalsIgnoreCase(""))
                  continue;
          }
      }
  }
  </code></pre>
  
  <p>I have this simple console program and I'm trying to implement Ctrl-C to simply quit. After a search I've had partial success using a shut down hook, however it's not working cleanly.</p>
  
  <p>With the line commented the program seems to loop a number of times before quitting (is this the main thread just looping itself?) and with the comment I get an exception on the next line's attempt to read the input stream.</p>
  
  <p>What's the best way to acheive this?</p>