System.IO.BinaryReader.Close 方法

方法描述

关闭当前阅读器及基础流。

语法定义(C# System.IO.BinaryReader.Close 方法 的用法)

public virtual void Close()

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
返回值 void

提示和注释

Close 的此实现调用传递 true 值的 Dispose 方法。

除非显式地调用 Flush 或 Close,否则,刷新流不会刷新其基础编码器。 将 AutoFlush 设置为 true 意味着将数据从缓冲区刷新到流中,但不刷新编码器状态。 这将允许编码器保持其状态(不完全字符),以便它可以正确地对下一个字符块进行编码。 此方案影响 UTF8 和 UTF7,这二者中,某些字符只能在编码器收到相邻的一个或多个字符后才能进行编码。

System.IO.BinaryReader.Close 方法例子

此代码示例摘自为 BinaryReader 类提供的一个更大的示例。

BinaryReader binReader =
    new BinaryReader(File.Open(fileName, FileMode.Open));
try
{
    // If the file is not empty,
    // read the application settings.
    // First read 4 bytes into a buffer to
    // determine if the file is empty.
    byte[] testArray = new byte[3];
    int count = binReader.Read(testArray, 0, 3);

    if (count != 0)
    {
        // Reset the position in the stream to zero.
        binReader.BaseStream.Seek(0, SeekOrigin.Begin);

        aspectRatio   = binReader.ReadSingle();
        lookupDir     = binReader.ReadString();
        autoSaveTime  = binReader.ReadInt32();
        showStatusBar = binReader.ReadBoolean();
    }
}

// If the end of the stream is reached before reading
// the four data values, ignore the error and use the
// default settings for the remaining values.
catch(EndOfStreamException e)
{
    Console.WriteLine("{0} caught and ignored. " +
        "Using default values.", e.GetType().Name);
}
finally
{
    binReader.Close();
}

异常

异常 异常描述

命名空间

namespace: System.IO

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。