为什么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(); } } 求高手指点hello world为什么死活不出现?只有手机摸拟器界面 循环里嵌套了线程,求验证 大侠,帮忙解决这个RCP问题,急~~~ unreachable statement ?? 大虾们这个问题怎么解决:java.net.SocketException: Connection reset(急!!!在线等) ResultSet问题 关于计算机图形学中的Mandelbrot集合,计算过程出问题。 问一个如何配置服务器,能够显示出Applet ▲▲▲发现java在文件处理方面有缺陷!▲▲▲▲ 请教 初学者对于多线程服务器程序的几点疑问??? 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();
}
}