---
title: "Stream Reader Object in C#"  
description: "In this blog, I’m trying to explain the concept of stream reader object and how to implement it .  StreamReaderreads text files. It is found in the Sy"  
author: "Sumit Kesarwani"  
published: 2013-05-18  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/514/stream-reader-object-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Stream Reader Object in C#

In this blog, I’m trying to [explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of stream reader object and how to implement it .\

**[StreamReader](https://www.mindstick.com/forum/1934/check-if-a-streamreader-can-read-another-line)** reads text files. It is found in the [System](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business).IO [namespace](https://www.mindstick.com/articles/12552/namespace). We have to wrap the [FileStream](https://www.mindstick.com/interview/34113/what-are-the-differences-between-filestream-flush-flushasync-and-dispose) object into StreamReader and use their [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) to manipulate files, but limitation with this is that [random access](https://answers.mindstick.com/qa/102433/can-you-detail-the-functions-of-a-computer-s-random-access-memory-ram) of file is not supported.

##### Example

```
using System;using System.IO;namespace StreamReaderConsoleApplication{    class streamReaderExample    {        static void Main(string[] args)        {            string str;            try            {                FileStream fs = new FileStream(@"D:\SumitKesarwani\sumit\2013-5-11\StreamReaderConsoleApplication\data.txt", FileMode.Open);                StreamReader sr = new StreamReader(fs);                str = sr.ReadLine();                while (str != null)                {                    Console.WriteLine(str);                    str = sr.ReadLine();                }                sr.Close();            }            catch(IOException e)            {                Console.WriteLine("Exception occured" + e.ToString());            }            Console.ReadLine();        }    }}
```

##

##

##

##### Output

![Stream Reader Object in C#](https://www.mindstick.com/blogs/4bfdd270-23aa-4ea1-9959-08ec2ce4a0a5/images/3d3beb95-2d7f-444a-b670-3ce42a6b39a7.jpg)

---

Original Source: https://www.mindstick.com/blog/514/stream-reader-object-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
