De-serializing objects from a file in Java
问题 I have a file which contains multiple serialized objects of class XYZ. While serializing, the each XYZ object was appended to the file. Now I need to read each object from the file, and I am able to read only the first object. Any idea how I can read each object from the file and eventually store it into a List? 回答1: Try the following: List<Object> results = new ArrayList<Object>(); FileInputStream fis = new FileInputStream("cool_file.tmp"); ObjectInputStream ois = new ObjectInputStream(fis);