获取文件数据流+叠加byte数组(给byte数组加包头包尾)
2016-10-08 16:42
176 查看
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
相关文章推荐
- java使用BZip算法压缩解压缩文件、数据流、byte[]字节数组
- java实现zlib压缩解压缩:文件、byte[]字节数组,数据流
- c#实现linux中gzip压缩解压缩算法:byte[]字节数组,文件,字符串,数据流的压缩解压缩
- 获取文件字节数组byte[]
- java实现linux中gzip压缩解压缩算法:byte[]字节数组,文件,字符串,数据流的压缩解压缩
- java使用tar算法压缩解压缩文件、数据流、byte[]字节数组
- 获取文件的byte数组与根据byte数组生成文件的工具类示例
- java byte数组与文件读写
- byte数组和文件的相互转换
- C# 将文件转化成byte[]数组
- 定义一个文件输入流,调用 read(byte[] b)方法将 exercise.txt 文件中的所有内容打印出来 (byte 数组的大小限制为 5)。
- mybatis中 mapper.xml文件中,获取数组中指定的位置的数据
- 安卓byte数组转图片文件
- 安卓byte数组转图片文件
- iOS学习(三十一)IOS中获取home文件的目录,分别保存字符串,数组,字典
- java 文件操作之byte数组间的转换
- 二级指针在函数中的应用(读取文件到BYTE*数组中)
- byte数组和文件读写
- byte数组转16进制 输出到文件
- C# 对象、文件与二进制串(byte数组)之间的转换