利用流来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. TrackBack URI

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word