Home > Article > Backend Development > Streams and byte streams in C#
#A file is a collection of data stored on disk with a specific name and directory path. When a file is opened for reading or writing, it becomes a stream.
The types of streams include:
Byte stream - including Stream, FileStream, MemoryStream and BufferedStream.
Character stream - Includes Textreader-TextWriter, StreamReader, StraemWriter and other streams.
Classes for byte streams treat the data in the stream as bytes.
The Stream class is the base class for other byte stream classes. The following are its properties:
CanRead - Whether the stream supports reading
CanWrite - Whether the stream supports writing
Length - The length of the stream
The System.IO namespace has various Classes that perform file-related operations such as creating and deleting files, reading or writing from files, closing files, etc.
The streams we discuss are described in the following table:
Serial number | I/O class and description |
---|---|
1 |
BinaryReader Reads raw data from a binary stream. |
2 |
BinaryWriter Write raw data in binary format. |
3 |
BufferedStream is used for temporary storage of byte streams. |
4 |
Directory is used to operate the directory structure. |
5 |
DirectoryInfo is used to perform operations on the directory. |
6 |
DriveInfo Provides drive information. |
7 |
File is used to operate files. |
8 |
FileInfo is used to perform operations on files. |
9 |
FileStream is used to read and write from any location in the file . |
10 |
MemoryStream Random for streaming data stored in memory access. |
11 |
Path Perform operations on path information. |
12 |
StreamReader is used to read characters from a byte stream. |
13 |
StreamWriter is used to write characters to the stream. |
14 |
StringReader is used to read from the string buffer. |
15 |
StringWriter is used to write to the string buffer. |
The above is the detailed content of Streams and byte streams in C#. For more information, please follow other related articles on the PHP Chinese website!