StreamWriter.Close 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
关闭当前 StreamWriter
对象和基础流。
public:
override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()
例外
当前编码不支持显示半个 Unicode 代理项对。
示例
下面的代码示例演示 了 Close
方法。
// close the file by closing the writer
sw->Close();
// close the file by closing the writer
sw.Close();
' Close the file by closing the writer.
Sw.Close()
注解
此方法重写 Stream.Close。
的此 Close 实现调用 Dispose 传递值的 true
方法。
必须调用 Close 以确保所有数据正确写入基础流。 调用 后 Close ,对 的任何操作 StreamWriter 都可能会引发异常。 如果磁盘上的空间不足,则调用 Close 将引发异常。
除非显式调用 或 ,否则刷新流不会刷新其基础编码 Flush 器 Close 。 设置为 AutoFlush true
表示数据从缓冲区刷新到流,但不刷新编码器状态。 这允许编码器保留其状态 (部分字符) 以便它可以正确编码下一个字符块。 这种情况会影响 UTF8 和 UTF7,其中某些字符只能在编码器收到相邻字符后进行编码。