FileStream.Length 屬性

定義

取得資料流的位元組長度。Gets the length in bytes of the stream.

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

屬性值

代表資料流長度的長數值 (以位元組為單位)。A long value representing the length of the stream in bytes.

例外狀況

這個資料流的 CanSeekfalseCanSeek for this stream is false.

發生 I/O 錯誤,例如檔案已關閉。An I/O error, such as the file being closed, occurred.

範例

下列範例會使用 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

備註

如需常見的檔案和目錄作業清單,請參閱一般 i/o工作。For a list of common file and directory operations, see Common I/O Tasks.

適用於

另請參閱