2013-02-21 35 views
0

在NetBeans显示此eroor错误在从TXT读取对象,并显示它

错误与I/O处理 java.io.WriteAbortedException:写入中止; java.io.NotSerializableException:katanemimena1.Account at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) at katanemimena1.ATM.actionPerformed(ATM的.java:208)

,我不明白为什么 这是代码

ObjectInputStream in =null; 
Account acc =null; 
try{ 
in =new ObjectInputStream(new FileInputStream("Accounts.txt")); 
while 
((acc = (Account) in.readObject()) !=null){ 
System.out.println(acc); 
} 
} 
catch(EOFException ex) { 
System.out.println("End of file reached."); 
} 
catch(ClassNotFoundException ex) { 
System.out.println("Error casting") ; 
ex.printStackTrace(); 
} 
catch(FileNotFoundException ex) { 
System.out.println("Error specified file does not exist") ; 
ex.printStackTrace(); 
} 
catch(IOException ex) { 
System.out.println("Error with I/O processes") ; 
ex.printStackTrace(); 
}finally{ 
try{ 
in.close(); 
} 
catch(IOException ex){ 
System.out.println("Another IOException during the closing"); 
ex.printStackTrace(); 
} 

    } 

回答

0

实现从java.io.Serializable接口

+0

很多感谢您的账户类,但知道是笑w我这[email protected] 但我想告诉我321 1066E帐户例如 – 2013-02-21 17:55:11

+0

因为你打印你的对象。的System.out.println(ACC);它默认调用object的toString()方法。你也可以通过实现toString()方法来覆盖这个功能并以任何格式打印你想要 – 2013-02-21 17:58:55

+0

谢谢你现在工作perfectt !!! – 2013-02-21 18:07:29