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.

适用于

另请参阅