Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BinaryReader.ReadByte()
Message
 
To
07/12/2004 07:11:08
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00967245
Message ID:
00967458
Views:
7
Cetin,
Thanks for your reply and code examples. What really helped and solved my problem was the fact that the FileStream object has Length and Position properties that I can use.

Thank you for your help

Sincerely,
Einar

>Einar,
>No particular reason. In notes I tried to mean that:) There are tons of classes, methods doing the same thing at the end. If I knew what you were doing after reading might come out with something totally different:)
>I didn't used ReadByte for one particular reason anyway, it reads one byte. Thought it'd not be efficient. ReadBytes OTOH might be more suitable for performance.
>In buffered read you can use any block size (4096 is also the smallest storage size on disk on most systems, and exact multiple of K etc). Whatever your actual data length is it works.
>Say you set buffer length as 1192 and actual data is 1193 bytes. It'd read the first 1192 bytes into buffer array. Then on next 'line' it'd only read 1 byte and rest of the buffer array elements would be the values left over previous read. Since using the return value intBytesRead you know how many array elements to check as part of actual data.
>Below is ReadByte,ReadBytes ways:
>
>using System;
>using System.IO;
>
>class test
>{
> public static void Main()
> {
>  string sFileName = "C:\\NMCC\\MWD\\data20041203134748.mwd";
>  test tester = new test();
>
>  Console.WriteLine("Reading in chunks");
>  tester.readBytes(sFileName);
>
>  Console.WriteLine("Reading byte by byte");
>  tester.readByte_By_Byte(sFileName);
> }
>
> public void readBytes(string sFileName)
> {
>  const int buflen=4096;
>  FileStream fs = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
>  BinaryReader br = new BinaryReader(fs);
>
>  while ( fs.Position < fs.Length ) // while not EOF
>  {
>     byte[] myBytes = br.ReadBytes(buflen); // request N bytes
>     Console.Write("Read {0} bytes:",myBytes.Length); // myBytes array length is the
>                                                      // actual number read
>     for(int i=0;i<myBytes.Length;i++)
>     {
>        Console.Write( "[{0,3}]",myBytes[i]);
>     }
>     Console.WriteLine();
>  }
>  fs.Close();
> }
>
> public void readByte_By_Byte(string sFileName)
> {
>  FileStream fs = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
>  BinaryReader br = new BinaryReader(fs);
>
>  while ( fs.Position < fs.Length )
>  {
>     Console.Write("[{0,3}]",br.ReadByte());
>  }
>  fs.Close();
> }
>}
>
>Cetin
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform