我正在做一个应该打开序列化文件并输出它的学校作业。我不知道为什么它不打印任何东西。循环似乎根本不起作用。有任何想法吗?
public ReadFile()
{
try
{
fis = new FileInputStream("Clients.ser");
ois = new ObjectInputStream(fis);
}
catch(Exception e) {}
try
{
while(true)
{
//cast according to class Record
r = (Record) ois.readObject();
System.out.print(r.account + r.firstName + r.lastName + r.balance);
}
}
catch(IOException ioe) { ioe.printStackTrace(); }
catch(ClassNotFoundException cnfe) {}
}
编辑
添加了一个堆栈跟踪IOException
并返回:
Record; local class incompatible: stream classdesc serialVersionUID = 5124020354301486787, local class serialVersionUID = -8881068308941519505