FileStream.Length 属性

定义

获取流的长度(以字节为单位)。

public:
 virtual property long Length { long get(); };
public override long Length { get; }
member this.Length : int64
Public Overrides ReadOnly Property Length As Long

属性值

表示流长度(以字节为单位)的长值。

例外

此流的 CanSeekfalse

出现 I/O 错误,例如文件被关闭。

示例

以下示例使用 LengthPosition 属性检查文件结尾条件。

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
    printfn "End of file has been reached."
If s.Length = s.Position Then
    Console.WriteLine("End of file has been reached.")
End If

注解

有关常见文件和目录操作的列表,请参阅 常见 I/O 任务

适用于

另请参阅