15.6. Readers and Writers

The Stream class and its subclasses are used for byte-level input/output. For actual character I/O, you should use System.IO.TextWriter and System.IO.TextReader.

The TextWriter class has several overloaded Write methods that write primitives to the underlying medium. All these methods write the primitive values as strings. The WriteLine method of this class writes the data and follows it with the line terminator character. The TextReader class has matching methods for reading data one character at a time (using the Read()method), reading a sequence of characters into a char[], or reading a line of characters.

You must be careful about using the ReadLine method; sometimes a line can be extremely long, and although the ...

Get .NET for Java Developers: Migrating to 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.