C# FileStream Length
Description
FileStream Length
Gets the length in bytes of the stream.
Syntax
FileStream.Length
has the following syntax.
public override long Length { get; }
Example
The following example uses the Length and Position properties to check for an end-of-file condition.
/*ww w .j a v a2 s . co m*/
using System;
using System.IO;
class TestRW
{
public static void Main(String[] args)
{
FileStream s = new FileStream("MyFile.txt", FileMode.OpenOrCreate, FileAccess.Read);
if( s.Length==s.Position )
{
Console.WriteLine("End of file has been reached.");
}
}
}
The code above generates the following result.