blogjava's web log

          blogjava's web log
          ...

          系列化例[導入]


          [Serializable]
          ????
          public?class?MyObject?
          ????
          {
          ????????
          public?int?n1?=?0;
          ????????
          public?int?n2?=?0;
          ????????
          public?String?str?=?null;
          ????}

          using?System;
          using?System.Drawing;
          using?System.Collections;
          using?System.ComponentModel;
          using?System.Windows.Forms;
          using?System.Data;
          using?System.IO?;
          using?System.Runtime?.Serialization?.Formatters?.Binary?;
          using?System.Runtime?.Serialization?;

          //系列化
          private?void?button1_Click(object?sender,?System.EventArgs?e)
          ????????
          {
          ????????????MyObject?obj?
          =?new?MyObject();
          ????????????obj.n1?
          =?1;
          ????????????obj.n2?
          =?24;
          ????????????obj.str?
          =?"Some?String";
          ????????????IFormatter?formatter?
          =?new?BinaryFormatter();
          ????????????Stream?stream?
          =?new?FileStream("MyFile.bin",?FileMode.Create,?FileAccess.Write,?FileShare.None);
          ????????????formatter.Serialize(stream,?obj);
          ????????????stream.Close();

          ????????}

          //反。。。。。。
          ????????private?void?button2_Click(object?sender,?System.EventArgs?e)
          ????????
          {
          ????????????IFormatter?formatter?
          =?new?BinaryFormatter();
          ????????????Stream?stream?
          =?new?FileStream("MyFile.bin",?FileMode.Open,?FileAccess.Read,?FileShare.Read);
          ????????????MyObject?obj?
          =?(MyObject)?formatter.Deserialize(stream);
          ????????????stream.Close();
          ????????????MessageBox.Show?(obj.n1.ToString?()?);

          ????????}

          posted on 2006-05-28 14:25 record java and net 閱讀(325) 評論(0)  編輯  收藏 所屬分類: dot net相關

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 临沭县| 吐鲁番市| 赣州市| 璧山县| 水富县| 怀宁县| 正定县| 武陟县| 达孜县| 杭锦旗| 西华县| 嘉义县| 台湾省| 井陉县| 调兵山市| 集安市| 浑源县| 廊坊市| 深州市| 板桥市| 宣化县| 五台县| 崇信县| 盐源县| 磐安县| 楚雄市| 垦利县| 齐齐哈尔市| 四子王旗| 宁强县| 牡丹江市| 高阳县| 江孜县| 偏关县| 上犹县| 临湘市| 左贡县| 天水市| 江阴市| 盐城市| 桑植县|