为什么objectoutputstream读取不到对象 stu1=(ArrayList<Student>)ois.readObject();,每次到这里,就会直接跳到catch,而不会直接读取对象,但是在show方法里面就可以读取到?本人新手,求大佬指点,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ArrayList<Student> stu1=null; Student stu=new Student(id, name, sex, classid, profession, birthday); try{ //while (true) { stu1=(ArrayList<Student>)ois.readObject(); //System.out.println(stu1.toString()); stu1.add(stu); oos.writeObject(stu1); System.out.println("OK"); //} } catch(EOFException e){ stu1=new ArrayList<Student>(); stu1.add(stu); oos.writeObject(stu1); System.out.println("OK"); } finally { fis.close(); ois.close(); } public static void show() throws Exception{ FileInputStream fis=new FileInputStream("Student.dat"); ObjectInputStream ois=new ObjectInputStream(fis); try{ while (true) { ArrayList<Student> stu1=(ArrayList<Student>)ois.readObject(); System.out.println(stu1.toString()); } } catch(EOFException e){ } finally { fis.close(); ois.close(); } } 请各位前辈帮帮小弟 时间模版? (转)被误解的C++——软件工程 ---- 大家评价一下这些c++“牛人”的观点 Java中如何判断一个字符是否是回车键? 急!!!在线等,问题很简单 一个editplus下的main参数问题 通过jdbc连接数据库,查询的记录有多少列(而不是行)? 关于JBuilder7 ,8的最基本问题,高分求救,不够再加!!!!!!!!! 请问在JAVA中怎样用图形(曲线)来表示各个时间段内的数据变化?(分不够,可再给) jps1.1.2(java pet store)问题 初学者对于多线程服务器程序的几点疑问??? java
Student stu=new Student(id, name, sex, classid, profession, birthday);
try{
//while (true) {
stu1=(ArrayList<Student>)ois.readObject();
//System.out.println(stu1.toString());
stu1.add(stu);
oos.writeObject(stu1);
System.out.println("OK");
//}
}
catch(EOFException e){
stu1=new ArrayList<Student>();
stu1.add(stu);
oos.writeObject(stu1);
System.out.println("OK"); }
finally {
fis.close();
ois.close();
}
FileInputStream fis=new FileInputStream("Student.dat");
ObjectInputStream ois=new ObjectInputStream(fis);
try{
while (true) {
ArrayList<Student> stu1=(ArrayList<Student>)ois.readObject();
System.out.println(stu1.toString());
}
}
catch(EOFException e){
}
finally {
fis.close();
ois.close();
}
}