- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Streams and Byte Streams in C#
A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream.
The type of streams includes −
Byte Streams − It includes Stream, FileStream, MemoryStream and BufferedStream.
Character Streams − It includes Textreader-TextWriter, StreamReader, StraemWriter and other streams.
Byte streams have classes that consider data in the stream as byte.
Stream class is the base for other byte stream classes. The following are the properties −
CanRead − Whether stream supports reading
CanWrite − Whether stream supports writing
Length − Length of the stream
The System.IO namespace has various classes that are used for performing numerous operations with files, such as creating and deleting files, reading from or writing to a file, closing a file etc.
The streams we discussed are described in the below table −
Sr.No | I/O Class & Description |
---|---|
1 | BinaryReader Reads primitive data from a binary stream. |
2 | BinaryWriter Writes primitive data in binary format. |
3 | BufferedStream A temporary storage for a stream of bytes. |
4 | Directory Helps in manipulating a directory structure. |
5 | DirectoryInfo Used for performing operations on directories. |
6 | DriveInfo Provides information for the drives. |
7 | File Helps in manipulating files. |
8 | FileInfo Used for performing operations on files. |
9 | FileStream Used to read from and write to any location in a file. |
10 | MemoryStream Used for random access to streamed data stored in memory. |
11 | Path Performs operations on path information. |
12 | StreamReader Used for reading characters from a byte stream. |
13 | StreamWriter Is used for writing characters to a stream. |
14 | StringReader Is used for reading from a string buffer. |
15 | StringWriter Is used for writing into a string buffer. |