Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Readkey in Java

I am new to Java ... is there a similar method to the ReadKey() in C# to avoid that a console application closes?

thanks

like image 941
mouthpiec Avatar asked Mar 28 '10 18:03

mouthpiec


2 Answers

One way to do it:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();

there are definitely shorter ones, but I think this one's convenient, because it can easily be extended.

like image 120
Chris Lercher Avatar answered Sep 28 '22 16:09

Chris Lercher


YOu can also use System.in.read(), if you are ok with just 'Enter' key being your exit key.

like image 21
Antony Thomas Avatar answered Sep 28 '22 17:09

Antony Thomas