Results 1 to 2 of 2

Thread: Having a problem with reading a binary file

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Having a problem with reading a binary file

    I dont know why I get this error. I simply want to read every byte of a binary file. I just declared a BinaryReader variable:
    VB Code:
    1. Dim strmSrc As FileStream = New IO.FileStream("c:\a.exe", FileMode.Open)
    2.         Dim brSrc As New BinaryReader(strmSrc)
    3.  
    4.      [color=red]   Do While brSrc.PeekChar <> -1[/color]
    5.             brSrc.ReadByte()
    6.         Loop

    if the file is small it works fine (like 10 KB) but when I test it with bigger files (200KB) it gives me this error:
    An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

    Additional information: Conversion buffer overflow.


    and the error happens on the red line, because of brSrc.PeekChar call. I don't understand why calling that could cause a problem. What am I doing wrong? I just want to read all the bytes in the file (this is just a sample code of course )
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Try changing <> - 1, to Do While brSrch.Peek >-1......
    Does it behave the same way???

    Failing that... look at the example MS code for reading.writing large files... OR, perhaps you're not Flushing the file stream before you close it (i know it should do that automatically, but just to eliminate the possiblity, put it in)... and make sure to seek the filestream to origin.

    http://samples.gotdotnet.com/quickst...eReadWrite.src
    Last edited by nemaroller; May 22nd, 2003 at 09:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width