`
changqingonly
  • 浏览: 25173 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

JAVA常用处理集锦

阅读更多
1、对象的深度clone方法
public static Object Clone(Object obj) throws Exception{
		
		Object nObj = null;
		
		try {
			ByteArrayOutputStream bout = new ByteArrayOutputStream();
			ObjectOutputStream out = new ObjectOutputStream(bout);
			out.writeObject(obj);
			out.close();
			
			ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
			ObjectInputStream in = new ObjectInputStream(bin);
			nObj = in.readObject();
			in.close();
		} catch (Exception e) {
			throw new Exception("Object inputed can't be cloned.");
		}
		return nObj;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics