0
以前分配的每个元素,我已经写了一个数组列表数据到所谓的(ItStateBinary.dat)爪哇 - 读从二进制文件的ArrayList集合,并在新的数组
的二进制文件,现在我想读的数组列表从二进制文件中,然后将arraylist中的每个元素分配给数组。
到目前为止我有此:
public CarOwner[] readListFromBinary() throws Exception
{
String fileName = "ItStateBinary.dat";
FileInputStream inStream = new FileInputStream(fileName);
ObjectInputStream objectInputFile = new ObjectInputStream(inStream);
//need to create CarOwner[] object called temp and return
}
readListFromBinary()方法从二进制文件(ltStateBinary.dat)读取一个ArrayList集合。然后,每个ArrayList对象项然后被写入一个新创建的名为temp的CarOwner []。 temp会返回到调用方法。
编辑:
public CarOwner[] readListFromBinary() throws Exception
{
String fileName = "ItStateBinary.dat";
FileInputStream inStream = new FileInputStream(fileName);
ObjectInputStream objectInputFile = new ObjectInputStream(inStream);
ArrayList<CarOwner> read = (ArrayList<CarOwner>)objectInputFile.readObject();
CarOwner[] temp = read.toArray(new CarOwner[read.size()]);
return temp;
}
没有任何人知道什么是错用这种方法?它给了我编译器警告