Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BinaryReader.ReadByte()
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
BinaryReader.ReadByte()
Divers
Thread ID:
00967245
Message ID:
00967245
Vues:
79
I am reading bytes from a data file using the ReadByte() method, but I am having some trouble finding out when the end of the data file has been reached. What I do now seems like a lot of work.
string sFileName = "C:\\NMCC\\MWD\\data20041203134748.mwd";

// Read the file using the stream reader to get the length of the file
System.IO.StreamReader oReader = System.IO.File.OpenText(sFileName);
string lcString = oReader.ReadToEnd();
oReader.Close();

// Use the length to the string to determine size of byte[]
System.Byte[] myByte = new System.Byte[lcString.Length];
System.IO.FileStream fs = new System.IO.FileStream(sFileName,System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);

// ReadByte() in a for loop
for (int i = 0 ; i < lcString.Length; i++)
{
	myByte[i] = r.ReadByte();
}
I know I can use the ReadBytes() method to get rid of the for loop but I would still need a way to find out how many bytes to read.

What would be nice is if I can use a while loop around the ReadByte() method, but the ReadByte() method returns a System.Byte and I can't find anything to test for to check if I have reached the end.

I can catch the an exception that the ReadByte() throws if the method is executed after EOF is reached.

Any help would be appreciated.

Thanks,
Einar
Semper ubi sub ubi.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform