Results 1 to 1 of 1
- 01-04-2009, 11:24 PM #1Member
- Join Date
- Jan 2009
- Rep Power
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.
Last edited by geeeeky.girl; 01-05-2009 at 12:06 AM.
- By sijokunnappilly in forum Advanced JavaReplies: 1Last Post: 10-30-2008, 08:59 AM
- By hkansal in forum New To JavaReplies: 4Last Post: 10-19-2008, 07:34 PM
- By xiechao in forum New To JavaReplies: 0Last Post: 04-22-2008, 12:57 PM
- By shaungoater in forum New To JavaReplies: 2Last Post: 03-10-2008, 05:18 PM
- By Khorod in forum New To JavaReplies: 1Last Post: 08-03-2007, 06:48 AM