Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

2 Questions on Reading Binary File; "Conversion buffer overflow"
Hi All,

What is the proper way to read a binary file into a byte[]?
I am using BinaryReader to read from a Stream and call the ReadByte method
of the BinaryReader object.

The method I'm using leads to the second question.  I got the "Conversion
buffer overflow" error when I run the following code:
Stream s = openFileDialog1.OpenFile();

System.IO.BinaryReader br = new BinaryReader(s);

byte[] ba = new byte[s.Length];    //    s.Length ~= 20000

while (br.PChar() > -1) {

ba[s.Position] = br.ReadByte();    //    <- s.Position ~= 400 when error
occurred

}

Thanks in advance





Report this thread to moderator Post Follow-up to this message
Old Post
poifull
05-25-05 08:59 AM


Re: 2 Questions on Reading Binary File; "Conversion buffer overflow"
Hi,


Take a look at this code:
int readed=0;
byte[] buff = new Byte[2048];
FileStream fstream = new FileStream( filename, FileMode.Open);

while( (readed=fstream.Read( buff, 0, 2048))>0 )
networkstream.Write( buff, 0, readed);
fstream.Close();


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"poifull" <poifull76@yahoo.com> wrote in message
news:kITke.128225$h6.79530@tornado.texas.rr.com...
> Hi All,
>
> What is the proper way to read a binary file into a byte[]?
> I am using BinaryReader to read from a Stream and call the ReadByte method
> of the BinaryReader object.
>
> The method I'm using leads to the second question.  I got the "Conversion
> buffer overflow" error when I run the following code:
> Stream s = openFileDialog1.OpenFile();
>
> System.IO.BinaryReader br = new BinaryReader(s);
>
> byte[] ba = new byte[s.Length];    //    s.Length ~= 20000
>
> while (br.PChar() > -1) {
>
>    ba[s.Position] = br.ReadByte();    //    <- s.Position ~= 400 when
> error occurred
>
> }
>
> Thanks in advance
>
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Ignacio Machin \( .NET/ C# MVP \)
05-26-05 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:31 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.