How to read serialized objects from file into ArrayList?

  • 0
    I write objects to a file through a loop without problems, but I don’t know how to read them back, because after a new program start, we don’t know how many objects are in the file.
    Java Anonymous, Aug 16, 2020

  • 1 Answers
  • 0
    If you are serializing yourself, then before writing the objects, write down the length of the array.

    for(Object o : list){

    And read like this:
    int size = in.readInt();
    for(int i = 0; i < size; i++){

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!