我有一个 ArrayList<ItemList>
其中 ItemList 为:
public class ItemList {
public ArrayList<Item> it = new ArrayList<Item>();
public String name = "";
public ItemList() {
}
}
该项的值为:
public class Item {
public String name = "";
public int count = 0;
public Item() {
}
}
我尝试对这个列表进行序列化:
try {
FileOutputStream fileOut = new FileOutputStream(sdDir + serFile);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(List_Of_Lists);
out.close();
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我认为它是有效的,因为我在文件夹中找到了这个文件。
但我无法将文件反序列化为ArrayList<ItemList>
代码:
try {
FileInputStream fileIn = new FileInputStream(sdDir + serFile);
ObjectInputStream in = new ObjectInputStream(fileIn);
List_Of_Lists = (ArrayList<ItemList>) in.readObject();
Log.i("palval", "dir.exists()");
in.close();
fileIn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
如何反序列化这个 ArrayList<ItemList>
?我总是遇到 IOException。