从txt读取对象时出错并显示它

时间:2013-02-21 17:34:37

标签: java

netbeans显示出这种eroor

  

I / O进程出错   java.io.WriteAbortedException:写入已中止; java.io.NotSerializableException:katanemimena1.Account       在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();
}

  }

1 个答案:

答案 0 :(得分:0)

从java.io.Serializable接口

实现您的Account类