0

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());
        }
    }
}
3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

in isnt working as it should

Please explain what the program does and what "is not working as it should" means.
Post the output from the program.

How do you test the code? Do you have a small complete program that compiles, excutes and shows the problem?

Edited by NormR1

0

Bah nm it was a matter of implementing the Serializable in the proper classes. =(

0

Please mark this "solved" so people don't waste time trying to help with it, and also so the problem & solution will be part of our knowledge base
J

Edited by JamesCherrill

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.