Home

StreamReader

StreamReader is a class in the .NET framework and .NET Core under the System.IO namespace. It provides a convenient way to read characters from a byte stream by decoding bytes into text using a specified character encoding. StreamReader buffers input to improve performance and is commonly used to read text from files, network streams, or memory streams.

Constructing a StreamReader can be done from a Stream or from a file path. Overloads allow specifying

Key reading operations include Read, Read(char[], int, int), ReadLine, and ReadToEnd, which provide character-by-character, block, line-based,

StreamReader is widely used in file I/O and text-processing scenarios, and is compatible with various stream

the
encoding,
whether
to
detect
encoding
from
a
byte
order
mark
(BOM),
buffer
size,
and
whether
to
leave
the
underlying
stream
open
when
the
reader
is
disposed.
The
CurrentEncoding
property
reveals
the
encoding
in
use,
and
the
BaseStream
property
exposes
the
underlying
stream.
By
default,
disposal
of
a
StreamReader
closes
the
underlying
stream,
unless
you
opt
to
leave
it
open.
or
complete-file
reads
respectively.
Asynchronous
variants—ReadAsync,
ReadLineAsync,
and
ReadToEndAsync—enable
non-blocking
I/O
in
applications
that
require
responsiveness
or
scalable
I/O.
The
EndOfStream
property
indicates
when
the
end
of
the
underlying
stream
has
been
reached.
sources,
including
FileStream,
MemoryStream,
and
network
streams.
It
remains
a
staple
for
developers
needing
robust,
encoding-aware
text
reading.
In
other
programming
environments,
similar
concepts
exist,
such
as
Java’s
InputStreamReader
and
Python’s
text
I/O
wrappers,
but
StreamReader
specifically
refers
to
the
.NET
implementation.