反序列化

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.Serialization.Formatters.Binary; //引入类库

using System.IO;

using ConsoleApplication6; //引入类所在的命名空间

 

namespace 反序列化

{

class Program

{

static void Main(string[] args)

{

BinaryFormatter bf = new BinaryFormatter();

using (FileStream fs = new FileStream("person.bin", FileMode.Open))

{

Object obj = bf.Deserialize(fs);

Person p = obj as Person;

Console.WriteLine(p.Name);

Console.WriteLine(p.Age);

Console.WriteLine(p.Email);

 

}

Console.WriteLine("ok");

Console.ReadKey();

}

}

}

上一篇:Unity Fileinfo和Directoryinfo以及File与Filestream还有Streamwriter和Streamreader


下一篇:C# FileStream设置了FileAccess.ReadWrite, FileShare.ReadWrite依然报“流不可读”或者“流不可写”