public static Member[] readObjectsFromFile(String filename) throws IOException
{
FileInputStream fileinputstream = new FileInputStream(filename);
ObjectInputStream inputstream = new ObjectInputStream(fileinputstream);
List<Member> list = new ArrayList<Member>();
int i = 0;
System.out.println(fileinputstream.available());
try
{
while(fileinputstream.available() > 0)
//改成 while(inputstream.available() > 0) 则不行
{
list.add((Member)inputstream.readObject());
i ++;
}
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
inputstream.close();
Member[] members = new Member[i];
members = list.toArray(members);
return members;
}
判断剩余字节数为什么用inputstream.available() > 0不行呢?实测时它就是返回0
------解决思路----------------------
http://bbs.csdn.net/topics/90153485