[英]“System.in.read()” in Java
我对此方法有疑问:
public void runTransaction(){
//Some calculations...
wait();
//Other calculations...
}
private static void wait(){
try {
System.out.println("Press <enter> to continue");
System.in.read();
}
catch (java.io.IOException ex) {
System.out.println("Input error...");
}
}
但是按Enter键后程序不会继续。 我正在使用Ubuntu 12.04。
编辑:该程序不会打印消息“按继续”,但此后不继续,它只是在等待输入。
您的代码是否可以编译? wait
方法在Object类上是公共的,因此不能将其重写为private。 尝试使用其他方法名称,例如waitForInput
。
如果您将名称更改为wait_enter,您的代码应按预期运行,您只需要确保在按Enter键之前单击控制台即可注册Enter键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.