Read from a text file one byte at a time in CSharp

Description

The following code shows how to read from a text file one byte at a time.

Example


         /*from  w  ww  . jav a2  s.  c  om*/

using System;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Threading;

public class MainClass
{
    public static void Main()
    {
        using (Stream s = new FileStream("c:\\test.txt", FileMode.Open))
        {
            int read;
            while ((read = s.ReadByte()) != -1)
            {
                Console.Write("{0} ", read);
            }
        }
    }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip