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("> ");
// if (in.hasNext())
input = in.nextLine();
if (input.equalsIgnoreCase(""))
continue;
}
}
}
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.
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.
What's the best way to acheive this?