Csharp/C Sharp/File Stream/Random Read — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:45, 26 мая 2010

Illustrates random access to a file

<source lang="csharp"> 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();
 }

}

      </source>