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

    /*              #########                       
                  ############                     
                  #############                    
                 ##  ###########                   
                ###  ###### #####                  
                ### #######   ####                 
               ###  ########## ####                
              ####  ########### ####               
             ####   ###########  #####             
            #####   ### ########   #####           
           #####   ###   ########   ######         
          ######   ###  ###########   ######       
         ######   #### ##############  ######      
        #######  #####################  ######     
        #######  ######################  ######    
       #######  ###### #################  ######   
       #######  ###### ###### #########   ######   
       #######    ##  ######   ######     ######   
       #######        ######    #####     #####    
        ######        #####     #####     ####     
         #####        ####      #####     ###      
          #####       ###        ###      #        
            ###       ###        ###              
             ##       ###        ###               
    __________#_______####_______####______________
        身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                    我们的未来没有BUG              
    * ==============================================================================
    * Filename: Text11
    * Created:  $time$
    * Author:   WYC
    * Purpose:  序列化和反序列化
    * ==============================================================================
    */
    using System;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    using UnityEngine;
    
    public class Text11 : MonoBehaviour {
    
        
        void Start () {
            //BinaryFormatterWrite();
            //BinaryFormatterRead();
        }
        public void BinaryFormatterRead()
        {
            PerSonqwer p = new PerSonqwer();
            using (FileStream fsRead = new FileStream(@"C:UsersAdministrator.PC-201709211725Desktop王1.txt", FileMode.OpenOrCreate, FileAccess.Read))
            {
                //开始反序列化
                BinaryFormatter bf = new BinaryFormatter();
                p = (PerSonqwer) bf.Deserialize(fsRead);
            }
            print("反序列化");
            print(p.Name);
            print(p.Age);
            print(p.Gender);
        }
    
    
        public void BinaryFormatterWrite() {
            PerSonqwer p1 = new PerSonqwer();
            p1.Name = "张三";
            p1.Age = 21;
            p1.Gender = "";
            using (FileStream fsWrite = new FileStream(@"C:UsersAdministrator.PC-201709211725Desktop王1.txt", FileMode.OpenOrCreate, FileAccess.Write))
            {
                //开始序列化
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fsWrite, p1);
                print("序列化");
            }
        }
    
    
        void Update () {
            
        }
    }
    [Serializable]
    public class PerSonqwer
    {
        public string Name;
        public int Age;
        public string Gender;
    }
  • 相关阅读:
    模拟登陆并爬取Github
    Python学习--猫眼电影TOP100榜单抓取
    MATLAB拟合和插值
    Python学习--两种方法爬取网页图片(requests/urllib)
    md5码加密(Python)
    【Docker】Dockerfile 之 ENTRYPOINT(三)
    【Docker】Dockerfile 之 ENTRYPOINT(二)
    CSS---选择器种类 | 层叠性权重
    HTML---引入css,js | 常用标签示例
    DB2批量插入性能对比
  • 原文地址:https://www.cnblogs.com/mclll520/p/8110711.html
Copyright © 2011-2022 走看看