Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / May 2005

Tip: Looking for answers? Try searching our database.

2 Questions on Reading Binary File; "Conversion buffer overflow"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
poifull - 25 May 2005 06:03 GMT
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.PeekChar() > -1) {

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

}

Thanks in advance
Ignacio Machin \( .NET/ C# MVP \) - 25 May 2005 13:50 GMT
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,

Signature

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

> Hi All,
>
[quoted text clipped - 18 lines]
>
> Thanks in advance

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.