qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

java使用序列化实现深克隆

public static Object deepClone(Object source) {
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
File file = null;
try {
FileOutputStream fos = new FileOutputStream("objFile");
oos = new ObjectOutputStream(fos);
oos.writeObject(source);
FileInputStream fis = new FileInputStream("objFile");
ois = new ObjectInputStream(fis);
return ois.readObject();
} catch (Exception e) {
System.err.println("对象克隆失败");
e.printStackTrace();
return null;
} finally {
try {
if(null != oos) {
oos.close();
}
if(null != ois) {
ois.close();
}
file = new File("objFile");
if(null != file) {
file.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

posted on 2013-10-14 10:08 顺其自然EVO 阅读(338) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年10月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜