方法已经是写好的,只需要传来参数就可以使用了,保存的格式是当前系统时间,年月日几点几分几秒,
若是加个定时器,还可以实现自动保存功能。
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();
}