Use the FileStream class to read from, write to, open, and close files on a file system
This is one of the classes derived from the Stream class.
File streams are buffered
Data is not written to a file when you write to the FileStream.

Once you have a filestream of the data you want you need to attach it to a Reader or Writer to be able to use it.
There are two options:
Plain Text - Use StreamReader and StreamWriter classes
Binary Data - Use BinaryReader and BinaryWriter classes

BeginReadstart an asynchronous operation on the stream
BeginWritestart an asynchronous operation on the stream
CloseCloses the stream
EndReadTo find out how many bytes were actually written
FlushEmpties the buferred stream and ensures all the contents are written
HandleReturns the operating system file handle
LengthReturns the total size of the stream. You can change the length using SetLength
LockLock a portion of the file
Positiondetermines the current position in the stream. You can change the position using Seek.
ReadReads a number of bytes from the specified position into a Byte array. The ReadByte method reads and returns a single byte.
SetLengthTrims or extends the underlying file.
UnlockUnlock a portion of the file
WriteWrites a number of bytes from an array into the stream. The WriteByte can write a single byte.

You can check which operations are allowed by using the CanRead, CanWrite and CanSeek properties.

System.IO.FileStream oFileStream; 
oFileStream = System.IO.FileStream("C:\Temp\textfile.txt",

   if (oFileStream.CanRead == true)

System.IO.FileMode.Append | Create | CreateNew | Open | OpenOrCreate | Truncate
System.IO.FileAccess.Read | Write | ReadWrite
System.IO.FileShare.None | ReadWrite | Read | Write | Inheritable

Using File.OpenRead

This is another way of obtaining a FileStream object.

System.IO.FileStream oFileStream; 
oFileStream = System.IO.File.OpenRead("C:\Temp\textfile.txt");

Stream Base Class


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext