Storing and Retrieving Data Using XStream & xml Files
I'm very frustrated, I've spent hours, probably an entire day in all, trying to find an extremely concise example of how to store and retrieve data using XStream / XML files. Before answering, please read on, and please keep in mind that I'm, relatively speaking, a beginner or advanced beginner.
Let's say I have an address book which contains a "Person.java" class (String name, String address, String phoneNumber) and an "AddressBook.java" class containing an ArrayList<Person> and possibly other fields. I also have a main or test class...
I want to save everything in the address book in an xml file using XStream and, more importantly, be able to retrieve the data.
First Question: WHERE?
I think what I want to do is create a save() and load() method (is that right?), however I don't know where to put them and how to use them! In the AddressBook class? Shall I call it everytime there is a change so that any changes are automatically saved? (in all setters and constructors)? What's the best way to organize this?
Second Question: WANTED: SIMPLE, CLEAR, CONCISE CODE WITH SIMPLE, CLEAR, CONCISE COMMENTS AND NO ADDITIONAL EXPLANATION, I BEG YOU!!!
I actually don't want an answer, code tells me much more than lengthy explanations. What I would like is working code that I could cut, paste and test for the above (save() and load() or whatever/however is the best way to do this.). The shorter, the better.
Thank you so much, and I really look forward to hearing from you.