java深克隆

public Object deepClone(Object obj) throws Exception{
		//将对象写入流
		ByteArrayOutputStream bo = new ByteArrayOutputStream();
		ObjectOutputStream oo = new ObjectOutputStream(bo);
		oo.writeObject(obj);
		//从流中读取对象
		ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
		ObjectInputStream bis = new ObjectInputStream(bi);
		return bis.readObject();
	}

你可能感兴趣的:(java)