A Stream is a group of continuous data that has the beginning and end, and uses a cursor to indicate the current position.
The data contained in the Stream can be from the memory MemoryStream, file FileStream, or the TCP/IP socket NetWorkStream.
Operations supported by the stream:
Read, data is transmitted from Stream to data structure (string or character segment array.
Write, data is transmitted from the data source to the Stream.
Search, query, and modify the position of your Stream.
Encoding> file and input/output> Stream> create a file Stream
Description: Creates a file path, and specifies the file mode, the access permission is FileAccess, and the shared access permission is FileShare.
Encoding> file and input/output> Stream> get and set file Stream attributes
Description to determine whether the Stream is readable. It can be set to writable.
Create a file stream to obtain and set file stream attributes. Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. IO;
Namespace FileStreamDemo1
{
Class Program
{
Static void Main (string [] args)
{
Const string FilePath = @ "C: MyData. dat ";
Using (FileStream fs = new FileStream (FilePath, FileMode. Create, FileAccess. ReadWrite, FileShare. Read ))
{
Console. WriteLine ("Whether the stream supports readable {0}", fs. CanRead );
Console. WriteLine ("does stream support writable {0}", fs. CanWrite );
Console. WriteLine ("does stream support {0}", fs. CanSeek );
Console. WriteLine ("the current stream Position is {0}", fs. Position );
Console. WriteLine ("Whether the stream is asynchronously opened {0}", fs. IsAsync );
Console. WriteLine ("the stream Length is {0}", fs. Length );
Fs. SetLength (20 );
Console. WriteLine ("new stream Length: {0}", fs. Length );
}
Console. ReadLine ();
}
}
}
Encoding> file and input/output> Stream> locate and read/write byte arrays to the file Stream
Locate and read/write byte arrays to file streams Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. IO;
Namespace FileStreamReadandwrite
{
Class Program
& Nbs