0
这里辍学是我的代码有:JAVA的ObjectInputStream不能从环
ObjectInputStream ois = null;
UserRegistration UR = new UserRegistration();
Scanner pause = new Scanner(System.in);
Admin go = new Admin();
try {
//ItemEntry book = new ItemEntry();
ois = new ObjectInputStream(new FileInputStream("Account.txt"));
while ((UR = (UserRegistration) ois.readObject()) != null) {
//if (book.getName().equals("1"))
{
System.out.println(UR);
}
}
} catch (EOFException e) {
System.out.println("\nEnd**");
}catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
try {
ois.close();
System.out.println("Press \"ENTER\" to continue...");
pause.nextLine();
go.startup();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
我怎样才能使它从环退出,而不是直接进入到EOFException类,当它到达的最后一个对象?请帮助 !
在没有任何异常之前,您不会进入catch块。 – Russiancold
为什么您需要退出循环?也许有更好的方法来完成你想要的东西。 –
我试过添加异常,但输出仍然保持不变。我不能在while循环之后做任何动作,导致它直接进入EOFException。 –