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


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


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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 新宾| 宁远县| 宜兰县| 金坛市| 泰来县| 壤塘县| 东乌珠穆沁旗| 金山区| 台山市| 龙山县| 康定县| 乐都县| 泰宁县| 英德市| 上高县| 京山县| 临泉县| 湖南省| 乌拉特后旗| 获嘉县| 沾化县| 闵行区| 新营市| 尼勒克县| 横山县| 花垣县| 扎赉特旗| 独山县| 明溪县| 宁明县| 衡南县| 玉屏| 锡林郭勒盟| 巴塘县| 土默特右旗| 荥阳市| 紫金县| 灵山县| 信宜市| 庆云县| 瑞金市|