I'm attempting to use the ObjectOutput/InputStream to write data to a file; I'm fairly certain I've got the out portion but coming back in isnt working as it should, thoughts?
public static void writePersistant(ArrayList<PersistantObject> persistantRecords) {
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("dataout/population-record.ser"));
for (PersistantObject i : persistantRecords) {
oos.writeObject(i);
}
oos.close();
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
System.out.println(ex.getStackTrace());
} catch (IOException ex) {
System.out.println(ex.getMessage());
System.out.println(ex.getStackTrace());
}
}
public static void readerPersistant() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("dataout/population-record.ser"));
Object inputObj = null;
while ((inputObj = ois.readObject()) != null) {
if (inputObj instanceof PersistantObject) {
System.out.println(inputObj);
}
}
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
System.out.println(ex.getStackTrace());
} catch (IOException | ClassNotFoundException ex) {
System.out.println(ex.getMessage());
System.out.println(ex.getStackTrace());
}
}
}