How to read file using StreamReader in C#?
How to read files using StreamReader in C#?
Content writing is the process of writing, editing, and publishing content in a digital format. That content can include blog posts, video or podcast scripts, ebooks or whitepapers, press releases, product category descriptions, landing page or social media copy and more.
Ashutosh Kumar Verma
13-Jun-2024C# StreamReader for Reading file
In C#, reading a file using the
StreamReader
class is simple.Example-
Here is a simple example to read data from text file using StreamReader class in C#,
In the above example-
File.Exists(filePath)
to check if the file exists.StreamReader
instance named reader and pass the file path to its constructor.ReadLine()
method of theStreamReader
instance.Output-
Also, Read: How to write file using StreamWriter in C#?