Users Online

· Guests Online: 122

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Get Content from a File and Read the Content 1 Byte at a Time

C# Program to Get Content from a File and Read the Content 1 Byte at a Time

 

This is a C# Program to get content from a file and read the content 1 byte at a time.

Problem Description

This C# Program Gets Content from a File and Read the Content 1 Byte at a Time.

Problem Solution

Here it firsts gets the contents from a file and reads the content per byte.

Program/Source Code

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();
        }
    }
}
Program Explanation

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.

Runtime Test Cases
 
71 79 79 68 77 79 82 78 73 78 71

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.91 seconds
10,853,772 unique visits