新手available方法问题
package aaaa;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
public class shiyan {
public static void main(String[] args) {
File wenjian=new File( "d:\\aaa.txt ");
ArrayList <lei> shuzu=new ArrayList <lei> ();
if (!wenjian.exists())
{
System.out.println( "文件不存在! ");
return;
}
try{
FileInputStream duqu = new FileInputStream(wenjian);
ObjectInputStream duqua = new ObjectInputStream(duqu);
while(duqu.available()> 0) //为什么把这里改成duqua.available()> 0就不行了?
{
shuzu.add((lei)duqua.readObject());
}
for (int i=0;i <shuzu.size();i++)
{
System.out.println(shuzu.get(i).getage());
System.out.println(shuzu.get(i).getname());
}
}catch(Exception e)
{
System.out.println( "出错了! ");
}
}
}
class lei implements Serializable
{
public lei(String name,int age)
{
this.name=name;
this.age=age;
}
private String name;
private int age;
public String getname()
{