I have to write the below binary array into a file:
byte[] data = new byte[] { 0x55, 0xAA, 0x02}; I want to put the exact data into the file (55,AA,02). Please let me know how to do it.
I have to write the below binary array into a file:
byte[] data = new byte[] { 0x55, 0xAA, 0x02}; I want to put the exact data into the file (55,AA,02). Please let me know how to do it.
You can use the Stream.Write(byte[] buffer) overload.
And even easier,
System.IO.File.WriteAllBytes("fileName", data); Please try the following:
FileStream fs = new FileStream(Application.StartupPath + "\\data.bin", FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); byte[] data = new byte[] { 0x55, 0xAA, 0x02 }; bw.Write(data); bw.Close(); fs.Close(); You can use File.WriteAllBytes(string path, byte[] bytes).