how to read byte array in c#

how to read byte array in c#

how to read byte array in c#

in order to know about how to read byte array in c#,we can use mentioned code in post .Reads a byte from the file and advances the read position one byte. You can use System.Text.Encoding 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#

 

 

 

 

 

 

 

 

 

For reference : how to read byte array in c# 

SHARE THIS

Leave a Reply

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