자바를 배우고 있고 파일의 레코드를 업데이트하는 방법을 썼습니다. 내가 겪고있는 문제는 사용자가 독자가 닫혀 있거나 입력을 지정할 수없는 다른 파일을 찾고 싶은지 묻는 것입니다.스트림이 닫히는 것과 관련된 이상한 오류
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))
감사를 사용 아무것도 입력에서 저를 차단 무엇 궁금.
편집 : 스캐너 오류를 사용
은 다음과 같습니다 BufferedReader로 오류를 사용 java.util.NoSuchElementException
은 다음과 같습니다 때 java.io.IOException : 코드에서 다른 곳이 있다면 스트림
정확한 오류 메시지는 무엇입니까? – Boann