操作后File.AppendAllText是否关闭文件
执行操作后,以下是否关闭文件? :
System.IO.File.AppendAllText(path, text);
是的,不,不够吗?
是的,它确实。
如果没有,之后就无法关闭它,因为它不会返回任何东西来处置。
来自文档 :
给定字符串和文件路径,此方法将打开指定的文件,将该字符串追加到文件的末尾,然后关闭该文件。
其他实用程序方法( ReadAllText
, WriteAllBytes
等)以相同的方式工作。
这是方法的代码:
public static void AppendAllText(string path, string contents, Encoding encoding) { using (StreamWriter writer = new StreamWriter(path, true, encoding)) { writer.Write(contents); } }
因此,是的。