1
我在读取文件时遇到问题,将文本更改为对象,然后将其添加到数组列表中。将文件中的对象读入arraylist
这是我读代码和写文件
public class ReadWrite {
public void save(String filename, ArrayList<Sale> buildings) throws IOException{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filename));
oos.writeObject(buildings);
oos.close();
}
public ArrayList<Sale> load(String filename) throws ClassNotFoundException, IOException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename));
buildings = (ArrayList<Sale>)ois.readObject();
ois.close();
return buildings;
}
}
的问题是
buildings = (ArrayList<Sale>)ois.readObject();
这是说,从对象的一个未经检查的强制转换为ArrayList中。通过论坛搜索这个问题,但似乎无法找到它
发布您的整个logcat – Kaushal28
显然会有一个未经检查的转换,但您的问题是您在使用它之前关闭了输入流。 –
这只是一个警告;忽略它。 – Bohemian