新手初学C#StreamWriter写文件,遇到点小问题,大家帮我看看啦~
问题:只能创建并写入第一个文件成功,第二个文件根本无法创建
FileStream fs;StreamWriter sw;string strContent;string strDir = @"D:\ST";string strPath;strPath = strDir + @"\S1.txt"; // S1.txt文件全路径fs = new FileStream(strPath, FileMode.OpenOrCreate);sw = new StreamWriter(fs, Encoding.Default);strContent = WriteToS1(); // 生成S1文件的内容sw.Write(strContent); strPath = strDir + @"S2.txt"; // S2.txt文件全路径fs = new FileStream(strPath, FileMode.OpenOrCreate);sw = new StreamWriter(fs, Encoding.Default);strContent = WriteToS2(); // 生成S2文件的内容sw.Write(strContent);sw.Close();