Use ObjectOutputStream and ObjectInputStream to write and read Hashtable
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.Hashtable;
public class Main {
public static void main(String[] args) throws Exception {
Hashtable h = new Hashtable();
h.put("string", "AAA");
h.put("int", new Integer(26));
h.put("double", new Double(Math.PI));
FileOutputStream fileOut = new FileOutputStream("hashtable.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(h);
FileInputStream fileIn = new FileInputStream("h.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
Hashtable h = (Hashtable)in.readObject( );
System.out.println(h.toString( ));
}
}
Related examples in the same category