Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import java.io.ByteArrayInputStream;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6.  
  7. public class _main implements Serializable{
  8. public _main deepClone() throws IOException, ClassNotFoundException {
  9. //将对象写入流中
  10. ByteArrayOutputStream bao=new ByteArrayOutputStream();
  11. ObjectOutputStream oos=new ObjectOutputStream(bao);
  12. oos.writeObject(this);
  13. //将对象从流中取出
  14. ByteArrayInputStream bis=new ByteArrayInputStream(bao.toByteArray());
  15. ObjectInputStream ois=new ObjectInputStream(bis);
  16. return (_main)ois.readObject();
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement