FileStream.Position FileStream.Position FileStream.Position FileStream.Position Property

定义

获取或设置此流的当前位置。Gets or sets the current position of this stream.

public:
 virtual property long Position { long get(); void set(long value); };
public override long Position { get; set; }
member this.Position : int64 with get, set
Public Overrides Property Position As Long

属性值

此流的当前位置。The current position of this stream.

异常

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

出现 I/O 错误。An I/O error occurred.

- 或 --or- 将位置设置为非常大的值,此值超出 Windows 98 或更早版本中的流的末尾。The position was set to a very large value beyond the end of the stream in Windows 98 or earlier.

试图将位置设置为负值。Attempted to set the position to a negative value.

试图越过不支持此值的流的末尾进行查找。Attempted seeking past the end of a stream that does not support this.

示例

下面的示例使用LengthPosition属性以检查是否为文件尾条件。The following example uses the Length and Position properties to check for an end-of-file condition.

if ( s->Length == s->Position )
{
   Console::WriteLine( "End of file has been reached." );
}
if( s.Length==s.Position )
{
   Console.WriteLine("End of file has been reached.");
}
If s.Length = s.Position Then
    Console.WriteLine("End of file has been reached.")
End If

注解

支持查找到流的长度超出任何位置。Seeking to any location beyond the length of the stream is supported. 如果要定位的文件的长度之外,文件大小的增长。When you seek beyond the length of the file, the file size grows. 在 Microsoft Windows NT 和更高版本,则将添加到文件末尾的所有数据都设置为零。In Microsoft Windows NT and newer, any data added to the end of the file is set to zero. 在 Microsoft Windows 98 或更早版本,添加到文件末尾的所有数据不会设置为零,这意味着,以前已删除的数据是可见的流。In Microsoft Windows 98 or earlier, any data added to the end of the file is not set to zero, which means that previously deleted data is visible to the stream. 将流的当前位置设置为在 Windows 98 或更早版本的流的末尾之外较大的值可能会导致引发异常。Setting the position of the stream to a large value beyond the end of the stream in Windows 98 or earlier may result in an exception being raised.

常见的文件和目录操作的列表,请参阅通用 I/O 任务For a list of common file and directory operations, see Common I/O Tasks.

适用于

另请参阅