【发布时间】:2018-09-10 03:50:52
【问题描述】:
当我在 while 循环块中调用 readLine() 时,不知何故,即使我按下了 enter,输入也不会完成。看起来,它创建了一个新行,但仍在等待行输入终止。
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String line = "";
while(!line.equals("End")){
line = br.readLine();
System.out.println("String from keyboard not working : "+line+"\n");
}
while((line = br.readLine())!=null) {
System.out.println("String from keyboard in while loop : "+line+"\n");
}
}
当我将 readline() 放在 while 的条件部分之上时,它可以正常工作。 我想知道为什么前者不起作用。
【问题讨论】:
标签: java bufferedreader