Click here to Skip to main content
15,883,961 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with Byte Pin
leppie7-Aug-08 3:32
leppie7-Aug-08 3:32 
GeneralRe: Problem with Byte Pin
softwarejaeger7-Aug-08 3:36
softwarejaeger7-Aug-08 3:36 
GeneralRe: Problem with Byte Pin
leppie7-Aug-08 3:43
leppie7-Aug-08 3:43 
GeneralRe: Problem with Byte Pin
#realJSOP7-Aug-08 4:19
mve#realJSOP7-Aug-08 4:19 
GeneralRe: Problem with Byte Pin
softwarejaeger7-Aug-08 3:58
softwarejaeger7-Aug-08 3:58 
AnswerRe: Problem with Byte Pin
#realJSOP7-Aug-08 4:16
mve#realJSOP7-Aug-08 4:16 
GeneralRe: Problem with Byte Pin
leppie7-Aug-08 5:15
leppie7-Aug-08 5:15 
GeneralRe: Problem with Byte [modified] Pin
#realJSOP7-Aug-08 5:50
mve#realJSOP7-Aug-08 5:50 
No, it won't, and I've got code to prove it. The function I'm calling returns an allocated array. That means I don't have to allocate it myself. However, I do have to initialize it to null so that it works on the first call.

BinaryReader reader       = null;
FileStream   streamSource = null;
byte[]       fileBytes    = null;

try
{
    streamSource  = new FileStream("c:\\myfile.dat", FileMode.Open, FileAccess.Read, FileShare.None);
    reader        = new BinaryReader(streamSource);

    do
    {
	fileBytes = reader.ReadBytes(65536);
	if (fileBytes.Length != 0)
	{
	    // do something...
	}
    } while (fileBytes.Length != 0);
}

catch (Exception ex)
{
    if (ex != null) {}
    this.m_lastError = 33;
}

finally
{
    if (reader != null)
    {
        reader.Close();
    }
    if (streamSource != null)
    {
        streamSource.Close();
    }
}


In the example I posted, fileBytes will contain one of three thins - a 65536-byte array, and n-byte array (comprised of the last bit of data in the file), or a 0-byte array, indicating no data read from the file (EOF).

In each of those three cases, the array is exactly the length of the retrieved data, and the array is never "null".


"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


modified on Thursday, August 7, 2008 12:12 PM

GeneralRe: Problem with Byte [modified] Pin
Daniel Grunwald7-Aug-08 6:24
Daniel Grunwald7-Aug-08 6:24 
AnswerRe: Problem with Byte Pin
Daniel Grunwald7-Aug-08 6:32
Daniel Grunwald7-Aug-08 6:32 
QuestionExcel Pin
ellllllllie7-Aug-08 3:11
ellllllllie7-Aug-08 3:11 
AnswerRe: Excel Pin
Indivara7-Aug-08 4:56
professionalIndivara7-Aug-08 4:56 
QuestionC# Packet Question Pin
Spiro Floropoulos7-Aug-08 2:29
Spiro Floropoulos7-Aug-08 2:29 
AnswerRe: C# Packet Question Pin
leppie7-Aug-08 2:51
leppie7-Aug-08 2:51 
GeneralRe: C# Packet Question Pin
Spiro Floropoulos7-Aug-08 2:58
Spiro Floropoulos7-Aug-08 2:58 
GeneralRe: C# Packet Question Pin
leppie7-Aug-08 3:02
leppie7-Aug-08 3:02 
GeneralRe: C# Packet Question Pin
leppie7-Aug-08 3:03
leppie7-Aug-08 3:03 
GeneralRe: C# Packet Question Pin
Spiro Floropoulos7-Aug-08 3:26
Spiro Floropoulos7-Aug-08 3:26 
GeneralRe: C# Packet Question Pin
leppie7-Aug-08 3:29
leppie7-Aug-08 3:29 
GeneralRe: C# Packet Question Pin
leppie7-Aug-08 4:19
leppie7-Aug-08 4:19 
QuestionDelete Object from Memory? Pin
softwarejaeger7-Aug-08 2:26
softwarejaeger7-Aug-08 2:26 
AnswerRe: Delete Object from Memory? Pin
Simon P Stevens7-Aug-08 2:42
Simon P Stevens7-Aug-08 2:42 
AnswerRe: Delete Object from Memory? Pin
#realJSOP7-Aug-08 2:44
mve#realJSOP7-Aug-08 2:44 
AnswerRe: Delete Object from Memory? Pin
Guffa7-Aug-08 2:55
Guffa7-Aug-08 2:55 
Questionthe operation could not be completed. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem Pin
laziale7-Aug-08 2:23
laziale7-Aug-08 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.