using System.IO; using System.Runtime.Serialization.Formatters.Binary; public class Serialize { static public void DoSerialize<T>(T obj, string path) { using (FileStream fs = new FileStream(path, FileMode.Create)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, obj); } } static public T DoDeSerialize<T>(string path) { FileInfo fi = new FileInfo(path); T t; try { using (FileStream fs = new FileStream(path, FileMode.Open)) { BinaryFormatter formatter = new BinaryFormatter(); t = (T)formatter.Deserialize(fs); } return t; } catch { return default(T); } } static public void SaveFile(string[] _content, string _path) { using (FileStream fs = new FileStream(_path, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { for (int i = 0; i < _content.Length; i++) { sw.WriteLine(_content[i]); } } } } }
,相关文章
- Java基础-IO流对象之序列化(ObjectOutputStream)与反序列化(ObjectInputStream)
- 孤荷凌寒自学python第三十七天python的文件与内存变量之间的序列化与反序列化
- c# 序列化效率比拼
- 序列化与反序列化成XML
- 关于C# XML序列化的一个BUG的修改
- C# Json数组序列化和反序列总结
- Day4 闭包、装饰器decorator、迭代器与生成器、面向过程编程、三元表达式、列表解析与生成器表达式、序列化与反序列化
- com.alibaba.fastjson.JSON对类对象的序列化与反序列化
- 模块讲解----json模块(跨平台的序列化与反序列化)
- 在C#中,Json的序列化和反序列化的几种方式总结