C# 读写txt文件(控制台程序)

2015-11-19 11:03:29

存在问题:
C# 如何读写txt文件


解决方案:
控制台程序如下

“`
string[,] contents = new string[3, 4];
contents[0, 1] = “fff”;
contents[2, 3] = “bbbbb”;
FileStream fs = new FileStream(@”e:\dd.txt”, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
//开始写入
sw.Write(contents[i, j] + ” “);
}
sw.Write(“\r\n”);
}

//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();“`

你可能感兴趣的:(软件类)