Answer the question
In order to leave comments, you need to log in
How to read serialized objects from file into ArrayList?
I write objects to a file without problems through a loop, but I don’t know how to count them back, because after a new start of the program, we don’t know how many objects are in the file.
Answer the question
In order to leave comments, you need to log in
If you are doing the serialization yourself, then before writing the objects, write down the length of the array.
data.writeInt(list.size());
for(Object o : list){
data.writeXXX(o);
}
int size = in.readInt();
for(int i = 0; i < size; i++){
list.add(in.readXXX());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question