BufferedStream.Seek(Int64, SeekOrigin) 方法


设置当前缓冲流中的位置。Sets the position within the current buffered stream.

 override long Seek(long offset, System::IO::SeekOrigin origin);
public override long Seek (long offset, System.IO.SeekOrigin origin);
override this.Seek : int64 * System.IO.SeekOrigin -> int64
Public Overrides Function Seek (offset As Long, origin As SeekOrigin) As Long



相对于 origin 的字节偏移量。A byte offset relative to origin.


SeekOrigin 类型的值,指示用于获得新位置的参考点。A value of type SeekOrigin indicating the reference point from which to obtain the new position.


当前缓冲流中的新位置。The new position within the current buffered stream.


流未打开或为 nullThe stream is not open or is null.

流不支持查找。The stream does not support seeking.

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


如果 offset 为负,则新位置位于 origin 指定的位置之前 offset 指定的字节数。If offset is negative, the new position will precede the position specified by origin by the number of bytes specified by offset. 如果 offset 是0,则新位置将是 origin指定的位置。If offset is 0, the new position will be the position specified by origin. 如果 offset 为正,则新位置位于 origin 指定的位置之后 offset 指定的字节数。If offset is positive, the new position will follow the position specified by origin by the number of bytes specified by offset.

BufferedStream 对象是 StreamReader 对象的基本流时,调用 Seek 方法会导致流的位置不再与读取器中内部缓冲区的位置匹配。When a BufferedStream object is the base stream for a StreamReader object, calling the Seek method can cause the position of the stream to no longer match the position of the internal buffer in the reader. 若要重置内部缓冲区,请调用 StreamReader.DiscardBufferedData 方法;但是,此方法会降低性能,只应在绝对必要时才调用。To reset the internal buffer, call the StreamReader.DiscardBufferedData method; however, this method slows performance and should be called only when absolutely necessary.

支持查找超出流长度的任何位置。Seeking to any location beyond the length of the stream is supported.