zoukankan      html  css  js  c++  java
  • 读取.dat数据文件

    public static Dictionary<string, serclass> dic_FarmCropsInfo = new Dictionary<string, serclass>();  //需要保存的对象

    /// <summary>
            /// 获取
            /// </summary>
            public static void GetFarmCropsInfo()
            {
                try
                {
                    string cropinfo_fn = AppDomain.CurrentDomain.BaseDirectory + "object.dat";
                    if (!File.Exists(cropinfo_fn))
                    {
                        File.Create(cropinfo_fn);
                    }
                    using (System.IO.FileStream fs = new System.IO.FileStream(cropinfo_fn, System.IO.FileMode.Open))
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        dic_FarmCropsInfo = bf.Deserialize(fs) as Dictionary<string, PayInfo>;
                    }
                }
                catch
                {
                }
            }

    /// <summary>
            /// 存储
            /// </summary>
            public static void SetFarmCropsInfo()
            {

    try            

    {               

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

       if (!File.Exists(cropinfo_fn))               

      {                  

       File.Create(cropinfo_fn);              

       }                

    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             {             }

    }

    public class serclass

    {

    ...

    }

  • 相关阅读:
    冒泡排序
    linux常用命令
    Github上将公共仓库转为私有仓库or私有仓库转为共有仓库
    使用apt更新和升级系统软件
    Django用户认证模块中继承AbstractUser与AbstractBaseUser重写User表的区别
    详解django中的collectstatic命令以及STATIC_URL、STATIC_ROOT配置
    python入门指南
    python包装不上?国内网络问题,使用豆瓣源解决
    nginx入门
    Vue 实现页面刷新(provide 和 inject)
  • 原文地址:https://www.cnblogs.com/Charles-xu/p/4913546.html
Copyright © 2011-2022 走看看