dat info是什么格式_dat格式_excel转换成dat格式

电脑杂谈  发布时间:2020-03-14 05:00:45  来源:网络整理

excel转换成dat格式_dat info是什么格式_dat格式

生成.dat文件,实际上就是运用C#的序列化方法操作而已。

给你一个例子,就是保存C#的对象作为.dat文件dat info是什么格式dat info是什么格式,注意这里保存的是一个Dictionary对象:

public static Dictionary dic_FarmCropsInfo = new Dictionary(); //需要保存的对象

1、读取文件信息

///

/// 获取作物信息

///

excel转换成dat格式_dat格式_dat info是什么格式

public static void GetFarmCropsInfo()

{

try

{

string cropinfo_fn = AppDomain.CurrentDomain.BaseDirectory + "CropsInfo.dat";

using (System.IO.FileStream fs = new System.IO.FileStream(cropinfo_fn, System.IO.FileMode.Open))

{

excel转换成dat格式_dat info是什么格式_dat格式

BinaryFormatter bf = new BinaryFormatter();

dic_FarmCropsInfo = bf.Deserialize(fs) as Dictionary;

}

}

catch { }

}

2、存储文件信息

dat info是什么格式_dat格式_excel转换成dat格式

///

/// 存储作物信息

///

public static void SetFarmCropsInfo()

{

try

{

excel转换成dat格式_dat info是什么格式_dat格式

string cropinfo_fn = AppDomain.CurrentDomain.BaseDirectory + "CropsInfo.dat";

using (System.IO.FileStream fs = new System.IO.FileStream(cropinfo_fn, System.IO.FileMode.OpenOrCreate))

{

BinaryFormatter bf = new BinaryFormatter();

bf.Serialize(fs, dic_FarmCropsInfo);

}

}

catch { }

}


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/shumachanpin/article-144085-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...