java读取和保存对象

Posted by Vincent on January 14, 2006

有这个东西,做缓存就很方便了

Map map = new HashMap();
FileOutputStream fos = new FileOutputStream("d:\\111.conf");
ObjectOutputStream o = new ObjectOutputStream(fos);
o.writeObject(map);
fos.close();
o.close();
FileInputStream fis = new FileInputStream(new File("d:\\111.conf"));
ObjectInputStream ois = new ObjectInputStream(fis);
Map map = (Map)ois.readObject();
System.out.println(map.size());
fis.close();
ois.close();

Published At: 2006-01-14 20:26:43 +0800