zoukankan      html  css  js  c++  java
  • 获取文件数据流+叠加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                 finally
    38                 {
    39                     //sr.Close();
    40                     //fs.Close();
    41                 }
    42             }
    View Code
  • 相关阅读:
    之前没弄明白的链表和return
    读Bsautiful Soup库有感
    Beautiful Soup库
    XML和JSON的系列操作
    urllib和requests的区别(持续更新)
    request请求把cookie当作参数传入请求
    Python统计文件夹下文件的个数
    基础算法之查找
    timeit用法(不完整)
    spring初识
  • 原文地址:https://www.cnblogs.com/acdyf/p/5939276.html
Copyright © 2011-2022 走看看