Tôi có một ArrayList<ItemList>
làm thế nào để serialize/deserialize ArrayList (Object)
nơi ItemList là:
public class ItemList {
public ArrayList<Item> it = new ArrayList<Item>();
public String name = "";
public ItemList() {
}
}
và khoản là:
public class Item {
public String name = "";
public int count = 0;
public Item() {
}
}
tôi cố gắng serialize danh sách này:
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();
}
Tôi thi nk đó là công việc, bởi vì tôi tìm thấy tập tin này trong thư mục.
Nhưng tôi không thể deserialize từ tập tin để ArrayList<ItemList>
mã:
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();
}
Làm thế nào tôi có thể deserialize ArrayList<ItemList>
này? Tôi luôn bắt IOException.
Vui lòng đăng toàn bộ stacktrace ngoại lệ – Tomer
Bạn có đang tuần tự hóa danh sách mảng chỉ có nghĩa là biến "nó" hoặc lớp ItemList không? – prashant
'Tôi luôn luôn bắt IOException'. Có nhưng bạn đã đọc tin nhắn chứa trong đó chưa? Nó chứa câu trả lời. – EJP