双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

压缩解压object对象

shsyzl007 shsyzl007 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我有两个函数,保存、读取object对象到磁盘文件。文件平均大小200M。
大神给封装下。保存和读取文件的时候压缩下。。
压缩幅度越大越好,尽量把文件压缩的小点。

 public static void SaveObject(object o, string filePath)
{
if (!Directory.Exists(filePath)) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); }
using (FileStream fs = new FileStream(filePath, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, o);
}
}

public static object ReadObject(string filePath)
{
object o;
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
o = bf.Deserialize(fs) as object;
}
return o;
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
shsyzl007
C# 111,129 成员 642,540 内容