獲取文件數據流+疊加byte數組(給byte數組加包頭包尾)
阿新 • • 發佈:2017-06-01
try 合並 文件 restore mode mem string 數據流 send
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 = newFileStream(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 finally 38 { 39 //sr.Close(); 40 //fs.Close(); 41 } 42 }
獲取文件數據流+疊加byte數組(給byte數組加包頭包尾)