1 /// <summary> 2 /// 二进制数组转流 3 /// </summary> 4 /// <param name="bytes"></param> 5 /// <returns></returns> 6 public static Stream BytesToStream(byte[] bytes) 7 { 8 Stream stream = new MemoryStream(bytes); 9 return stream; 10 } 11 12 /// <summary> 13 /// 流转二进制数组 14 /// </summary> 15 /// <param name="theStream"></param> 16 /// <returns></returns> 17 public static byte[] StreamToBytes(Stream theStream) 18 { 19 int index; 20 MemoryStream tempStream = new MemoryStream(); 21 while ((index = theStream.ReadByte()) != -1) 22 { 23 tempStream.WriteByte(((byte)index)); 24 } 25 return tempStream.ToArray(); 26 }
时间: 2024-10-13 08:52:14