Reading and Writing Data
Reading and writing data is accomplished with the Stream
class. Remember streams? This is a chapter about streams.[18]
Stream
supports synchronous and asynchronous reads and writes. The .NET Framework provides a number of classes derived from Stream
, including FileStream
, MemoryStream
, and NetworkStream
. In addition, there is a BufferedStream
class that provides buffered I/O, and can be used with any of the other stream classes. Table 22-5 summarizes the principal classes involved with I/O.
Table 22-5. Principal I/O classes of the .NET Framework
Class | Use |
---|---|
Stream | Abstract class that supports reading and writing bytes |
BinaryReader/BinaryWriter | Read and write encoded strings and primitive datatypes to and from streams |
File, FileInfo, Directory, DirectoryInfo | Provide implementations for the abstract |
FileStream | For reading to and from |
TextReader, TextWriter, StringReader, StringWriter |
|
BufferedStream | A stream that adds buffering to another stream such as a |
Get Programming C# 3.0, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.