S.O. S.O. -5 years ago 208
Java Question

Make the console wait for an user input to close

sorry about the seemingly stupid question, but I just can't seem to find the right keywords to find this answer. It's pretty simple: I have a console application that after performing its tasks, must give a feedback to the user, such as "operation completed" or "operation failed" and the detailed error. The thing is, if I just "let it run", the output message will be printed but console will close shortly afterwards, leaving no time to read the message. As far as I remember, in C++, every console application will end with a "press any key to exit" or something like that. In C# I can simulate this behavior with a


But how can I do it in Java? I'm using the Scanner class, but given that "input" is my instance of Scanner:


"Any key" will work, except for return, which is quite a big deal here. Any pointers?

Answer Source

In Java this would be System.in.read()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download