eofexception解决方法socket(问一问:eofexception解决方法socket)
1、在用到文件的地方加上try catch就可以了!import ***.io.*;import java.util.*;class file {try{ File f=...
eofexception解决方法socket

1、在用到文件的地方加上try catch就可以了!import ***.io.*;import java.util.*;class file {try{ File f=null;FileInputStream fips=null;ObjectOutputStream oops=null;public filethrows Exception{ f=new File("d:"+File.separator+"resource.txt"); if(!f.exists) f.createNewFile; fips=new FileInputStream(f); oops=new ObjectOutputStream(new FileOutputStream(f)); if(***.read==-1){fips.close; List l=new ArrayList;oops.writeObject(l); oops.close;}}public void save(Object o)throws Exception{ ObjectOutputStream oops1=null; oops1=new ObjectOutputStream(new FileOutputStream(f)); @SuppressWarnings("unchecked") List per=(List)this.load; per.add((Person)o); oops.writeObject(per); oops.close; }public Object loadthrows Exception{ ObjectInputStream oips=new ObjectInputStream(new FileInputStream(f)); @SuppressWarnings("unchecked") List per2=(List)oips.readObject; oips.close;return per2; } }catch(Exception){}}public class main {public static void main(String[] args)throws Exception {file f=new file;f.save(new Person("小明",12));f.save(new Person("小红",11));}}。

