zoukankan      html  css  js  c++  java
  • 序列化

    序列化: 对象-->流-->保存到文件

    一个类要想被序列化,必须加 [Serializable]标识为可序列化
    二进制序列化器:
    命名空间:
    using System.Runtime.Serialization.Formatters.Binary;
    类:
    BinaryFormatter
    ------------使用二进制序列化器进行序列化
    StudentData data = new StudentData();
    data.Code = TextBox1.Text;
    data.Name = TextBox2.Text;
    data.Sex = TextBox3.Text;
    data.Nation = TextBox4.Text;

    FileStream fs = null;

    try
    {
    string path = Server.MapPath("data/aaa.txt");
    fs = new FileStream(path, FileMode.Create);

    //开始使用序列化,将对象序列化到流中去
    BinaryFormatter bf = new BinaryFormatter();
    bf.Serialize(fs, data);//序列化的方法

    }
    finally
    {
    if(fs!=null)
    {
    fs.Close();
    }
    }


    反序列化:流-->对象
    -----使用二进制序列化器,进行反序列化
    string path = Server.MapPath("data/aaa.txt");
    FileStream fs = null;
    try {
    fs = new FileStream(path,FileMode.Open);
    //从流中反序列化出对象
    BinaryFormatter bf = new BinaryFormatter();
    StudentData data = (StudentData)bf.Deserialize(fs);

    TextBox1.Text = data.Code;
    TextBox2.Text = data.Name;
    TextBox3.Text = data.Sex;
    TextBox4.Text = data.Nation;
    }
    finally
    {
    if (fs != null)
    {
    fs.Close();
    }
    }


    ------SOAP序列化

  • 相关阅读:
    iptables
    iftop
    sed&awk
    rz&sz
    关于springboot + mybatis plus 使用事务
    关于JsonArray.toList转换
    jmeter脚本录制
    去掉百度右边的百度热搜等干扰项,集中注意力呀~~
    报错
    图片的异步上传
  • 原文地址:https://www.cnblogs.com/981971554nb/p/4506567.html
Copyright © 2011-2022 走看看