This is a C# Program to get content from a file and read the content 1 byte at a time.
This C# Program Gets Content from a File and Read the Content 1 Byte at a Time.
Here it firsts gets the contents from a file and reads the content per byte.
Here is source code of the C# Program to Get Content from a File and Read the Content 1 Byte at a Time. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Get Content from a File and Read the Content 1 Byte at a Time */ using System; using System.IO; public sealed class Program { public static void Main() { using (Stream s = new FileStream(@"c:\sri\srip.txt", FileMode.Open)) { int read; while ((read = s.ReadByte()) != -1) { Console.Write("{0} ", read); } Console.ReadLine(); } } }
This C# program is used to get content from a file and read the content 1 byte at a time. Using ReadByte() function, we are reading a byte from the file and advances the read position one byte.
While loop is used to check the line is not equal to -1. If the condition is true then execute the iteration of the loop. Here it firsts gets the contents from a file and reads the content per byte and print the value.
71 79 79 68 77 79 82 78 73 78 71
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- 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
- Practice Computer Science MCQs
- Buy Computer Science Books
- Buy MCA Books
- Buy C# Books
- Apply for Computer Science Internship