序列化与反序列化

来源:互联网 发布:production i.g 知乎 编辑:程序博客网 时间:2024/06/18 07:14
private void FileSerialize()        {            try            {                FileStream fs = new FileStream(PICCOUNT, FileMode.Create);                BinaryFormatter sl = new BinaryFormatter();                sl.Serialize(fs, _PicCount);                fs.Close();            }            catch(Exception ex)            {                MessageBox.Show(ex.Message);            }        }        private void FileDeSerialize()        {            if (System.IO.File.Exists(PICCOUNT))            {                try                {                    FileStream fs = new FileStream(PICCOUNT, FileMode.Open, FileAccess.Read, FileShare.Read);                    BinaryFormatter sl = new BinaryFormatter();                    object obj= (PicCount)sl.Deserialize(fs);                    fs.Close();                    PicCount pic = obj as PicCount;                    if (pic != null) this._PicCount = pic;                                                        }                catch (Exception ex)                {                    MessageBox.Show(ex.Message);                    this._PicCount=null;                }            }            else            {                this._PicCount = null;            }        }

0 0
原创粉丝点击