Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- public class _main implements Serializable{
- public _main deepClone() throws IOException, ClassNotFoundException {
- //将对象写入流中
- ByteArrayOutputStream bao=new ByteArrayOutputStream();
- ObjectOutputStream oos=new ObjectOutputStream(bao);
- oos.writeObject(this);
- //将对象从流中取出
- ByteArrayInputStream bis=new ByteArrayInputStream(bao.toByteArray());
- ObjectInputStream ois=new ObjectInputStream(bis);
- return (_main)ois.readObject();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement