G O O D M O R N I N G
Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Program to Read Data from Stream and Convert Data to Chars
C# Program to Read Data from Stream and Convert Data to Chars
This is a C# Program to read data from stream and cast data to chars.
This C# Program Reads Data from Stream and Cast Data to Chars.
Here the string from the file is converted into character data.
Here is source code of the C# Program to Read Data from Stream and Cast Data to Chars. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Read Data from Stream and Cast Data to Chars */ 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} ", (char)read); } Console.ReadLine(); } } }
This C# program is used to read data from stream and cast data to chars. The ReadByte() function is used to read a byte from the file and advances read the position one byte. Using while loop checks the line is not equal to -1. If the condition is true then execute the iteration of the loop. The string from the file is converted into character data.