O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Text File Input and Output with StreamReader and StreamWriter

The StreamReader and StreamWriter classes are specially designed to represent character streams and contain members that make reading from and writing to text files convenient. These streams can only be used with text files. A few of their methods are shown in Tables 22.3 and 22.4.

Both stream classes contain a method called Close that closes the related stream. This releases the resources allocated to the stream and allows other parts of the program access to the underlying file (usually only one stream can access a file at any one time). Furthermore, a stream that is left unclosed without an associated running program is prone to be damaged.

Even if you don't close a stream explicitly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required