In a Java console application, I would like to handle Ctrl+C by printing:
Do you really want to exit (y,N)?
Terminate normally when 'y' is pressed but continue running if anything else is pressed.
Is this possible in Java?
Original
I know how to shutdown Java application gracefully by adding shutdown hook, or how to handle signals like interrupt or TERM.
The problem here is, in C, when I handle the interrupt I can force the app to exit or to just print a message and continue working. I want to do something like this. When you press Ctrl+C, I ask you do you really want to exit (y,n).
However, in Java I see that all I can do is write something before exiting, so I will always exit no matter what. What is the solution to this problem?