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;
    }
  • 相关阅读:
    [bzoj3224] 普通平衡树
    [总结] 三种常见的区间贪心问题
    [NOIP2014] 飞扬的小鸟
    POJ 1185 炮兵阵地
    WOJ 1538 Stones II 转化背包问题
    WOJ 1542 Countries 并查集转化新点+最短路
    UVA 11375 高精度Bign类
    2014_csu选拔1_B
    Codeforces 405D 数学问题
    Codeforces 400C 矩阵乘法 数学规律
  • 原文地址:https://www.cnblogs.com/mclll520/p/8110711.html
Copyright © 2011-2022 走看看