FileStream实现了IDisposable,这意味着你必须调用Dispose。请看上一个问题 我是否需要处理FileStream对象?
MS自己告诉你这个 https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream?view=netframework-4.7.2
最简单的方法是使用“using”语句
using (FileStream fs = File.Create(path)) { AddText(fs, "This is some text"); AddText(fs, "This is some more text,"); AddText(fs, "\r\nand this is on a new line"); AddText(fs, "\r\n\r\nThe following is a subset of characters:\r\n"); for (int i=1;i < 120;i++) { AddText(fs, Convert.ToChar(i).ToString()); } }