S
Siva
how would i read a binary file into a byte array efficiently?
how would i read a binary file into a byte array efficiently?
Siva said:how would i read a binary file into a byte array efficiently?
Family Tree Mike said:Siva said:how would i read a binary file into a byte array efficiently?
byte [] data = File.ReadAllBytes("Somefilename.bin");
Mike
Siva said:thanks and how do convert this byte[] to string?
Siva said:thanks and how do convert this byte[] to string?
Kerem Gümrükcü said:Hi Siva,
how would i read a binary file into a byte array efficiently?
this is the fastest way to do it in one shot:
byte[] yourFileBytes = File.ReadAllBytes(@"C:\Path\To\Your\File.txt");
Regards
Kerem
--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
Siva said:hello,
Sorry for the confusion, here is the code,
byte[] data = File.ReadAllBytes(<filepath>);
MD5 md5 = MD5.Create();
byte[] hash = md5.ComputeHash(data);
now i need to convert this 'hash' to string with hexadecimal representation.
is a ready made method available already?
Siva
Siva said:Sorry for the confusion, here is the code,
byte[] data = File.ReadAllBytes(<filepath>);
MD5 md5 = MD5.Create();
byte[] hash = md5.ComputeHash(data);
now i need to convert this 'hash' to string with hexadecimal
representation.
is a ready made method available already?
Depending on the exact format you want, you could do something like:
foreach (byte b in hash)
Console.WriteLine(b.ToString("x"));
I'd amend that to
Console.WriteLine(b.ToString("x:2"))
So that all bytes will be 2 characters, or those pesky less-than-16 bytes
will screw up your string.
I'd amend that to
Console.WriteLine(b.ToString("x:2"))