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


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


          網站導航:
           
          <2013年10月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 光山县| 余庆县| 札达县| 南和县| 剑川县| 东山县| 华池县| 汨罗市| 高雄市| 镇巴县| 疏附县| 奉新县| 卢氏县| 荔波县| 湟中县| 那曲县| 湾仔区| 黔西| 潞西市| 紫金县| 友谊县| 庄河市| 库车县| 靖西县| 抚顺县| 双牌县| 绥棱县| 吉隆县| 肃北| 北票市| 苍梧县| 手机| 汝阳县| 平谷区| 砀山县| 修水县| 鹤峰县| 林周县| 宜州市| 汝南县| 唐河县|