This is a C# Program to use streamreader to read entire line.
Problem Description
This C# Program Uses StreamReader to Read Entire Line.
Problem Solution
Here with the help of streamreader it reads and displays the entire line from the file.
Program/Source Code
Here is source code of the C# Program to Use StreamReader to Read Entire Line. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Use StreamReader to Read Entire Line */ using System; using System.IO; using System.IO.Compression; using System.Text; public sealed class Program { public static void Main() { Stream s = new FileStream(@"c:\sri\srip.txt", FileMode.Open); using (StreamReader sr = new StreamReader(s, Encoding.UTF8)) { string line; while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } Console.ReadLine(); } } }
Program Explanation
This C# program is used to use StreamReader to read the entire line. It reads with the help of StreamReader, using while loop checks the line is not equal to null. If the condition is true, then execute the iteration of the loop. Print the entire line from the file.
advertisement
advertisement
Runtime Test Cases
StreamWriter writes text files. It enables easy and efficient text output. It is best placed in a using-statement to ensure it is removed from memory when no longer needed. It provides several constructors and many methods.
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
If you wish to look at all C# Programming examples, go to 1000 C# Programs.
Next Steps:
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy C# Books
- Practice MCA MCQs
- Apply for C# Internship
- Buy MCA Books
- Practice Computer Science MCQs