qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          java使用序列化實現(xiàn)深克隆

          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 閱讀(344) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          <2013年10月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 綦江县| 万盛区| 黔东| 连平县| 平昌县| 石阡县| 石首市| 大同市| 沁阳市| 拉萨市| 右玉县| 怀柔区| 安吉县| 沅陵县| 广安市| 罗定市| 惠来县| 娄底市| 襄城县| 林甸县| 英吉沙县| 广南县| 谷城县| 浙江省| 扶风县| 宁化县| 曲麻莱县| 隆子县| 嘉荫县| 南川市| 高台县| 邹平县| 察隅县| 东丽区| 扬州市| 信阳市| 乐安县| 宜宾县| 汉中市| 丹棱县| 湘乡市|