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

屬性值

Int64

代表資料流長度的長數值 (以位元組為單位)。

例外狀況

這個資料流的 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
    Console.WriteLine("End of file has been reached.")
End If

備註

如需常見的檔案和目錄作業清單,請參閱 一般 i/o工作。

適用於

另請參閱