利用流来clone对象

Posted by 猪头小队长 | 程序设计 | Thursday 23 September 2004 18:11

现在需要clone的对象是HashMap needCloneMap,要将其clone为cloneMap.

操作如下:

ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objectout = new ObjectOutputStream(out);
objectout.writeObject(needCloneMap);

ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ObjectInputStream objectin = new ObjectInputStream(in);
HashMap cloneMap = (HashMap) objectin.readObject();

克隆完毕。

[@more@]

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.