File pointer move and read binary file : Binary Read Write « File Stream « C# / C Sharp






File pointer move and read binary file

  

using System;
using System.IO;
using System.Text;

class Class1{
  static void Main(string[] args)  {
         byte[] byData = new byte[100];
         char[] charData = new Char[100];

         try {
            FileStream aFile = new FileStream("practice.txt",FileMode.Open);
            aFile.Seek(55,SeekOrigin.Begin);
            aFile.Read(byData,0,100);
         }
         catch(IOException e)
         {
            Console.WriteLine("An IO exception has been thrown!");
            Console.WriteLine(e.ToString());
            Console.ReadLine();
            return;
         }

         Decoder d = Encoding.UTF8.GetDecoder();
         d.GetChars(byData, 0, byData.Length, charData, 0);

         Console.WriteLine(charData);
         return;
  }
}

           
         
    
  








Related examples in the same category

1.Binary Writer Reader
2.new BinaryReader(stream)
3.StreamWriter and BinaryWriter
4.new BinaryWriter(stream) and Write method
5.Creating a sequential-access file
6.Reading a sequential-access fileReading a sequential-access file
7.BinaryWriter and BinaryReader classes for the writing and reading of primitive typesBinaryWriter and BinaryReader classes for the writing and reading of primitive types
8.Working with the BinaryWriter Class
9.Working with the BinaryReader ClassWorking with the BinaryReader Class
10.Write and then read back binary dataWrite and then read back binary data
11.Use BinaryReader and BinaryWriter to implement a simple inventory programUse BinaryReader and BinaryWriter to implement 
   a simple inventory program
12.Read the data from a file and desiralize it
13.Read and Write a Binary File
14.Read Struct out of a file with BinaryReader
15.extends BinaryReader
16.Write a value at a given position. Used to write a size of data in an earlier located header.