System.IO.EndOfStreamException 类

方法描述

读操作尝试超出流的末尾时引发的异常。

语法定义(C# System.IO.EndOfStreamException 类 的用法)

[SerializableAttribute]
[ComVisibleAttribute(true)]
public class EndOfStreamException : IOException

构造函数

构造函数名称 构造函数描述
EndOfStreamException() 初始化 EndOfStreamException 类的新实例,将其消息字符串设置为系统提供的消息,其 HRESULT 设置为 COR_E_ENDOFSTREAM。
EndOfStreamException(String) 初始化 EndOfStreamException 类的新实例,使其消息字符串设置为 message,其 HRESULT 设置为 COR_E_ENDOFSTREAM。
EndOfStreamException(SerializationInfo, StreamingContext) 使用指定的序列化和上下文信息初始化 EndOfStreamException 类的新实例。
EndOfStreamException(String, Exception) 使用指定错误信息和对作为此异常原因的内部异常的引用来初始化 EndOfStreamException 类的新实例。

成员/方法

方法名称 方法描述
Equals(Object) 确定指定的 Object 是否等于当前的 Object。 (继承自 Object。)
Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
GetBaseException 当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。 (继承自 Exception。)
GetHashCode 用作特定类型的哈希函数。 (继承自 Object。)
GetObjectData 当在派生类中重写时,用关于异常的信息设置 SerializationInfo。 (继承自 Exception。)
GetType 获取当前实例的运行时类型。 (继承自 Exception。) 在 XNA Framework3.0GetType()。 在 GetType()。
MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
ToString 创建并返回当前异常的字符串表示形式。 (继承自 Exception。)

提示和注释

EndOfStreamException 使用值为 0x80070026 的 HRESULT COR_E_ENDOFSTREAM。

System.IO.EndOfStreamException 类例子

下面的代码示例说明如何通过在 MemoryStream 类之上使用 BinaryReader 和 BinaryWriter 两个类,在内存中读写 Double 数据。

using System;
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i;
        const int arrayLength = 1000;

        // Create random data to write to the stream.
        Random randomGenerator = new Random();
        double[] dataArray = new double[arrayLength];
        for(i = 0; i < arrayLength; i++)
        {
            dataArray[i] = 100.1 * randomGenerator.NextDouble();
        }

        using(BinaryWriter binWriter = 
            new BinaryWriter(new MemoryStream()))
        {
            // Write the data to the stream.
            Console.WriteLine("Writing data to the stream.");
            for(i = 0; i < arrayLength; i++)
            {
                binWriter.Write(dataArray[i]);
            }

            // Create a reader using the stream from the writer.
            using(BinaryReader binReader = 
                new BinaryReader(binWriter.BaseStream))
            {
                try
                {
                    // Return to the beginning of the stream.
                    binReader.BaseStream.Position = 0;

                    // Read and verify the data.
                    Console.WriteLine("Verifying the written data.");
                    for(i = 0; i < arrayLength; i++)
                    {
                        if(binReader.ReadDouble() != dataArray[i])
                        {
                            Console.WriteLine("Error writing data.");
                            break;
                        }
                    }
                    Console.WriteLine("The data was written " +
                        "and verified.");
                }
                catch(EndOfStreamException e)
                {
                    Console.WriteLine("Error writing data: {0}.",
                        e.GetType().Name);
                }
            }
        }
    }
}

继承层次结构

System.Object

System.Exception

System.SystemException

System.IO.IOException

System.IO.EndOfStreamException

命名空间

namespace: System.IO

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

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

版本信息

.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 系统要求。