|
-
May 22nd, 2003, 02:05 PM
#1
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:
Dim strmSrc As FileStream = New IO.FileStream("c:\a.exe", FileMode.Open)
Dim brSrc As New BinaryReader(strmSrc)
[color=red] Do While brSrc.PeekChar <> -1[/color]
brSrc.ReadByte()
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!!
-
May 22nd, 2003, 09:44 PM
#2
I wonder how many charact
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|