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.
|BeginRead||start an asynchronous operation on the stream|
|BeginWrite||start an asynchronous operation on the stream|
|Close||Closes the stream|
|EndRead||To find out how many bytes were actually written|
|Flush||Empties the buferred stream and ensures all the contents are written|
|Handle||Returns the operating system file handle|
|Length||Returns the total size of the stream. You can change the length using SetLength|
|Lock||Lock a portion of the file|
|Position||determines the current position in the stream. You can change the position using Seek.|
|Read||Reads a number of bytes from the specified position into a Byte array. The ReadByte method reads and returns a single byte.|
|SetLength||Trims or extends the underlying file.|
|Unlock||Unlock a portion of the file|
|Write||Writes 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.
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
This is another way of obtaining a FileStream object.
oFileStream = System.IO.File.OpenRead("C:\Temp\textfile.txt");
Stream Base Class
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext