Answers for "reading multiple objects from file in java"

0

reading multiple objects from file in java

FileInputStream fis = new FileInputStream("outputFile");
ArrayList<Object> objectsList = new ArrayList<>();
boolean cont = true;
while (cont) {
  try (ObjectInputStream input = new ObjectInputStream(fis)) {
    Object obj = input.readObject();
    if (obj != null) {
      objectsList.add(obj);
    } else {
      cont = false;
    }
  } catch (Exception e) {
    // System.out.println(e.printStackTrace());
  }
}
Posted by: Guest on August-13-2020

Code answers related to "reading multiple objects from file in java"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language