Chapter 11. Files and Streams
At some stage in your development cycle, you need to store data on some persistent media so that when the computer is restarted the data is still be available. In most cases, you either store the data in a database or in files. A file is basically a sequence of characters stored on storage media such as your hard disks, thumb drives, and so on. When you talk about files, you need to understand another associated term — streams. A stream is a channel in which data is passed from one point to another. In .NET, streams are divided into various types: file streams for files held on permanent storage, network streams for data transferred across the network, memory streams for data stored in internal storage, and so forth.
With streams, you can perform a wide range of tasks, including compressing and decompressing data, serializing and deserializing data, and encrypting and decrypting data. This chapter examines:
Manipulating files and directories
How to quickly read and write data to files
The concepts of streams
Using the
BufferedStreamclass to improve the performance of applications reading from a streamUsing the
FileStreamclass to read and write to filesUsing the
MemoryStreamclass to use the internal memory store as a bufferUsing the
NetworkStreamclass for network programmingThe various types of cryptographic classes available in .NET
Performing compressions and decompression on streams
Serializing and deserializing objects into binary and XML data