1.对象实现Serializable接口
2.将对象通过对象输出流输出,在反序列
public Object getClone() throws IOException, ClassNotFoundException { ByteArrayOutputStream bio = new ByteArrayOutputStream();//字节流的形式输出 ObjectOutputStream oos = new ObjectOutputStream(bio);//对象流接受字节流 oos.writeObject(this);//将当前对象序列化 ByteArrayInputStream bis = new ByteArrayInputStream(bio.toByteArray());//接收一个字节数组 ObjectInputStream ois = new ObjectInputStream(bis);//将字节流读入对象流 DeepSheep o = (DeepSheep) ois.readObject(); return o; }
浙公网安备 33010602011771号