Readkey in Java

假如想象 提交于 2019-12-21 04:04:47

问题


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

thanks


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2533987/readkey-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!