System.IO.FileStream
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
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.
System.IO.FileStream oFileStream;
oFileStream = System.IO.FileStream("C:\Temp\textfile.txt",
System.IO.FileMode.Open,
System.IO.FileAccess.Read,
System.IO.FileShare.Read);
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
System.IO.Stream
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext