Readkey in Java

2020-06-16 02:51发布

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

thanks

2条回答
仙女界的扛把子
2楼-- · 2020-06-16 03:29

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

查看更多
乱世女痞
3楼-- · 2020-06-16 03:32

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.

查看更多
登录 后发表回答