filestream_ReadByte.htm
This example shows how to read single byte from a file, till end of the document. Each time advancing form  the current position of the stream by one byte of upstream .


using System;
using System.IO;
using System.Text;
//csc filestream_readbyte.cs
//C:\MySharp\file_stream\MyTest.txt
namespace file_stream
{
public class read_to
{
public static void process(string s1)
{

int i;
FileStream fs;

try {
fs = new FileStream(s1, FileMode.Open);
} catch(FileNotFoundException exc) {
Console.WriteLine(exc.Message);
return;
}
// Reading single Byte from the file till EOF
do {
try {
i = fs.ReadByte();
} catch(Exception e) {
Console.WriteLine(e.Message);
return;
}
if(i != -1) Console.Write((char) i);
} while(i != -1);

fs.Close();
}
}

class Test
{
static void Main()
{

Console.Write("enter file and path :");
string str1 = Console.ReadLine();
read_to.process(str1);
Console.ReadLine();
}
}
}