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 工作

適用於

另請參閱