Illustrates random access to a file : Random Read : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » Random Read »

 

Illustrates random access to a file








    

using System;
using System.IO;

public class RandomAccess {
  public static void Main(String[] args) {
    FileStream fileStream = new FileStream("test.cs", FileMode.Open);
    fileStream.Seek(20, SeekOrigin.Begin);
    
    byte[] anInt = new byte[4];
    fileStream.Read(anInt,0,4);
    int number = anInt[3];
    
    for(int i = 2; i >= 0; i--){
      number *= 256;
      number += anInt[i];
    }     
    Console.WriteLine("The number starting at byte 20 is {0}",  number);
    fileStream.Close();
  }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» Random Read