Streams


All input and output in the .NET Framework involves the use of streams. A stream is an abstract representation of a serial device. A serial device is something that stores data in a linear manner and is accessed the same way: 1 byte at a time. This device can be a disk file, a network channel, a memory location, or any other object that supports reading and writing to it in a linear manner. Keeping the device abstract means that the underlying destination/source of the stream can be hidden. This level of abstraction enables code reuse and allows you to write more generic routines, since you don't have to worry about the specifics of how data transfer actually occurs. Therefore, similar code can be transferred and reused when the application is reading from a file input stream, a network input stream, or any other kind of stream. Because you can ignore the physical mechanics of each device, you don't need to worry about, for example, hard disk heads or memory allocation when dealing with a file stream.

There are two types of stream:

  • Output streams: These are used when data is written to some external destination. This can be a physical disk file, a network location, a printer, or another program. Understanding stream programming opens many advanced possibilities. In this chapter, you are concentrating on file system data, so you'll only be looking at writing to disk files.

  • Input streams: These are used to read data into memory or variables that your program can access. The most common form of input stream you have worked with so far is the keyboard. An input stream can come from almost any source, but in this chapter you concentrate on reading disk files. The concepts applied to reading/writing disk files will apply to most devices, so you'll gain a basic understanding of streams and see a proven approach that can be applied to many situations.




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net