首页 > 代码库 > 获取文件数据流+叠加byte数组(给byte数组加包头包尾)

获取文件数据流+叠加byte数组(给byte数组加包头包尾)

技术分享
 1 OpenFileDialog ofd = new OpenFileDialog(); 2             ofd.Filter = "(*.mp4)|*.mp4|(*.*)|*.*"; 3             ofd.RestoreDirectory = true; 4             if (ofd.ShowDialog() == DialogResult.OK) 5             {   6                 try 7                 { // 打开文件  8  9                     FileStream fileStream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);10 11                     // 读取文件的 byte[] 12                      13                     byte[] brecord = new byte[fileStream.Length]; 14                     fileStream.Read(brecord, 0, brecord.Length); 15                     byte[] data1 = { 123, 66, 69, 83, 84, 69, 76 };16                     byte[] data2 = { 76, 69, 83, 84, 69, 76, 125 };17 18                     var data3 = new byte[data1.Length + data2.Length + brecord.Length];19                     Stream s = new MemoryStream();20                     s.Write(data1, 0, data1.Length);21                     s.Write(brecord, 0, brecord.Length);22                     s.Write(data2, 0, data2.Length);23                     s.Position = 0;24                     int r = s.Read(data3, 0, data3.Length);25                     if (r > 0)26                     {27                         //此时data3中就是合并的值了28                     }29                     mc.Send(data3);30                     31                     fileStream.Close();  32                 }33                 catch (Exception ex)34                 {35                     MessageBox.Show(ex.Message.ToString());36                 }37                 finally38                 {39                     //sr.Close();40                     //fs.Close();41                 }42             }
View Code

 

获取文件数据流+叠加byte数组(给byte数组加包头包尾)