码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-06-01 15:15:21      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:文件   bsp   pen   nbsp   ogr   code   catch   var   read   

 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                 finally
38                 {
39                     //sr.Close();
40                     //fs.Close();
41                 }
42             }

 

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

标签:文件   bsp   pen   nbsp   ogr   code   catch   var   read   

原文地址:http://www.cnblogs.com/dyfisgod/p/6928928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!