c# binaryreader

c# binaryreader

We will  Know about how we use “c# binaryreader” . Reads a byte from the file and advances the read position one byte. You can use System.Text.Encoding the class to convert between string and byte array. Based on the encoding of your input string/byte array, use the appropriate property from this class. We see the syntax for calling File.ReadAllBytes. The method returns a byte array, which will be stored in the large object heap if it is large. The array can, of course, be used as any other byte[] type. We get a byte array from a file.

Public static byte[] GetBytesFromFile(this string PhysicalFilePath)
{
FileStream stream = null;
byte[] buffer;
try
{
stream = File.OpenRead(PhysicalFilePath);
buffer = new byte[stream.Length];
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
}
catch
{
buffer = new byte[0];
}
finally
{
if (stream != null)
{
stream.Close();
stream.Dispose();
}
}
return buffer;
}

 

how to read byte array in c#

 

 

 

 

 

 

 

 

 

Conclusion

I hope you liked this article aboutc# binaryreader. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

SHARE THIS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.