Hi
try this out
public class Storing {
public static void main(String[] args) {
store();
fetch();
}
private static void store() {
Hashtable h = new Hashtable();
h.put("A", "chiru");
h.put("B", "Nag");
h.put("C", "Venki");
try {
FileOutputStream fileOut = new FileOutputStream("hello.txt");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(h);
out.close();
fileOut.close();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void fetch() {
Hashtable h = null;
try {
FileInputStream fileIn = new FileInputStream("Hello.txt");
ObjectInputStream in = new ObjectInputStream(fileIn);
h = (Hashtable)in.readObject();
in.close();
fileIn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
for (Enumeration e = h.keys(); e.hasMoreElements(); ) {
Object obj = e.nextElement();
System.out.println(" Values: " + h.get(obj));
}
}
}
--Raj
|