菜鸟求助!!哪位大神能帮我看看~谢谢!

weixin_36780214 weixin_36780214 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
	public void Test2(){
ObjectInputStream o=null;
Person p4;
try {
o=new ObjectInputStream(new FileInputStream("liuliu.txt"));
Object oo=o.readObject();
p4=(Person)o.readObject();
System.out.println( p4);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
o.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}


下面是出现错误的原因
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at 对象序列化和反序列化.Test2(对象序列化和反序列化.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
weixin_36780214
Java SE 62,621 成员 307,251 内容