BufferedStream.ReadByte 方法

定义

从基础流中读取一个字节,并返回转换为 int 的该字节;或者如果从流的末尾读取则返回 -1。Reads a byte from the underlying stream and returns the byte cast to an int, or returns -1 if reading from the end of the stream.

public:
 override int ReadByte();
public override int ReadByte ();
override this.ReadByte : unit -> int
Public Overrides Function ReadByte () As Integer

返回

转换为 int 的字节,或者如果从流的末尾读取则为 -1。The byte cast to an int, or -1 if reading from the end of the stream.

异常

发生 I/O 错误,如流被关闭。An I/O error occurs, such as the stream being closed.

流不支持读取。The stream does not support reading.

在流关闭后调用方法。Methods were called after the stream was closed.

继承者说明

Stream 上的默认实现创建新的单字节数组,然后调用 Read(Byte[], Int32, Int32)The default implementation on Stream creates a new single-byte array and then calls Read(Byte[], Int32, Int32). 尽管这是正确的,但效率低下。While this is formally correct, it is inefficient. 具有内部缓冲区的任何流都应该重写此方法,并提供一个更高效的版本来直接读取缓冲区,避免在每次调用时进行额外的数组分配。Any stream with an internal buffer should override this method and provide a much more efficient version that reads the buffer directly, avoiding the extra array allocation on every call.

适用于

另请参阅