I am not real solid on this, but with the Collections interface can't you implement a hashmap, for example, and then use an ObjectOutputStream linked to a FileOutputStream to write the hashmap to a file and then reverse it with an ObjectInputStream linked to a FileInputStream to re-instantiate that data at a later time? Here is a snippet of code I found in the Collections tutorial at Javasoft regarding this:
import java.io.*;
import java.util.*;
public class serial1 {
public static void main(
String args[]) {
Map hm = new HashMap();
hm.put("Mary", "123-4567");
hm.put("Larry", "234-5678");
hm.put("Mary", "456-7890");
hm.put("Felicia", "345-6789");
try { FileOutputStream fos = new FileOutputStream("test.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(hm);
oos.close();
}
catch (Throwable e) {
System.err.println(e);
}
}
}
import java.io.*;
import java.util.*;
public class serial2 {
public static void main(String args[]) {
Map hm = null;
try { FileInputStream fis = new FileInputStream("test.ser"); ObjectInputStream ois = new ObjectInputStream(fis);
hm = (Map)ois.readObject();
ois.close();
}
catch (Throwable e) {
System.err.println(e);
}
if (hm != null) {
Iterator iter = hm.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry e = (Map.Entry)iter.next();
System.out.println(e.getKey() + " " + e.getValue());
}
}
}
}
--Octavyn