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。 –