【发布时间】:2015-01-11 07:42:30
【问题描述】:
我正在学习 Java,我编写了一个方法来更新文件中的记录。我遇到的问题是,当我询问用户是否要查找另一个文件时,我的阅读器已关闭或无法为其分配任何输入。
protected boolean Update() throws InputMismatchException
{
RoomService Init =new RoomService();
Scanner input = new Scanner(System.in);
try {
boolean ans= true;
while(ans)
{
System.out.println("Please enter room number.");
String id = input.next();
Init.Update(id);
System.out.println("Press Enter to Add more or no to exit");
String choice = input.nextLine();// Skips this line
if (choice.equalsIgnoreCase(""))
{
continue;
}
else if(choice.equalsIgnoreCase("no"))
{
ans= false;
}
else
{
System.err.println("Wrong input");
throw new IOException();
}
}
} catch (IOException e) {
e.printStackTrace();
fail=true;
}
return fail;
}
想知道究竟是什么阻止我输入我也使用过的任何东西BufferedReader input = new BufferedReader(new InputStreamReader (System.in))
谢谢。
编辑:
使用扫描仪错误是:java.util.NoSuchElementException
使用 BufferedReader 错误是:java.io.IOException: Stream closed
【问题讨论】:
-
您得到的确切错误信息是什么?
标签: java input stream java.util.scanner bufferedreader