Streams

A common programming task is to read data from or write data to files, network sockets, or some other devices. The BCL formalizes this behavior by means of an abstract class Stream (namespace System.IO). Table 5.2 shows some frequently used methods available on this class.

Table 5.2. Some Methods Available on System.IO.Stream
MethodDescription
CanSeekCan you seek to a position within the stream?
CanReadCan the stream be read?
CanWriteCan the stream be written to?
LengthLength of the stream.
PositionCurrent cursor position.
SeekSeek to a position.
ReadRead bytes from the stream.
WriteWrite bytes to the stream.
FlushFlush any buffered data to the underlying device.
CloseClose the stream and release any resources (such as sockets and file handles). ...

Get .NET Programming: A Practical Guide Using C# 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.