C# int二维数组保存txt文件格式

来源:互联网 发布:双时标网络计划图 编辑:程序博客网 时间:2024/05/21 13:06
方法已经是写好的,只需要传来参数就可以使用了,保存的格式是当前系统时间,年月日几点几分几秒,

若是加个定时器,还可以实现自动保存功能。


        public void write(int[,] arr)             //保存txt文本        {            //获取当前时间 年月日时分秒  大写的MM是月,小写的mm是分钟 ss是秒            string name = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss");            //保存地址为D盘,文件名根据系统时间自创            FileStream fs = new FileStream("D:\\测试\\" + name + ".txt", FileMode.Create);            StreamWriter sw = new StreamWriter(fs);            //初始化二维数组s 用来接收arr            int[,] s = new int[48, 56];            //接收arr            s = arr;            for (int l = 0; l < 48; ++l)            {                for (int h = 0; h < 56; ++h)                {                    //s的每个值和arr的每个值对应                    s[l, h] = arr[l, h];                    int output;                    output = Convert.ToInt32(s[l, h]);                    //有个空格作为间隔,                    sw.Write(output + " ");                }                sw.WriteLine();            }            //清空缓冲区            sw.Flush();            //关闭流            sw.Close();            fs.Close();        }


原创粉丝点击