`
zhangyeny
  • 浏览: 31934 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

java序列化深度克隆

 
阅读更多
    publicObject copy() throwsIOException, ClassNotFoundException{
        //将对象序列化后写在流里,因为写在流里面的对象是一份拷贝,
        //原对象仍然在JVM里
        ByteArrayOutputStream bos = newByteArrayOutputStream();
        ObjectOutputStream oos = newObjectOutputStream(bos);
        oos.writeObject(this);
         
        ObjectInputStream ois = newObjectInputStream(newByteArrayInputStream(
                bos.toByteArray()));
        returnois.readObject();
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics