文件写入方法:public void writeObjectM(Object obj) throws Exception{ String file = "D:/1/data/Manager.dat"; ObjectOutputStream ooc = new ObjectOutputStream( new FileOutputStream(file)); ooc.writeObject(obj); ooc.flush(); ooc.close(); }//下面这种写入没有问题。Manager [] ma = {new Manager(1,2,"aaa"),new Manager(1,3,"bbb")};writeObjecM(ma);//因为程序中用到了ArrayList DB,在后面从ArrayList 保存对象到文件就不会了。。。Object m[] = readObjectM(); for (int i = 0; i < m.length ; i++){ Manager a = (Manager)m[i]; DB.add(a); }//程序中修改了对象的属性,将对象再次保存到文件中就出错了。。。writeObjectM(DB);和for (int i = 0 ; i < DB.size(); i++) { Manager s = (Manager) DB.get(i); writeObjectM(s); }都出现问题,程序一开始的读入出错,学期大作业,真是不会改了,求大神帮忙。orz
添加回答
举报
0/150
提交
取消