members.bin
文件中有许多对象,但是当我调用此方法时,此列表只返回一个对象。
我怎样才能在二进制文件中写入对象,以便每行只有一个对象?
public ArrayList<Member> getInfo(){
FileInputStream fis ;
ObjectInputStream ois = null;
Member member ;
ArrayList<Member> list = new ArrayList<>();
try {
fis = new FileInputStream("members.bin");
ois = new ObjectInputStream(fis);
while((member = (Member)ois.readObject()) != null ){
list.add(member);
}
} catch (IOException ex){
System.out.println("IOException 1");
} catch(ClassNotFoundException ex) {
System.out.println("ClassNotFoundException");
}finally{
try {
ois.close();
} catch (IOException ex) {
System.out.println("IOException 2");
}
}
return list;
}