Stream 和 byte[] 之间的转换

        /// <summary>
        /// byte转换Stream
        /// </summary>
        /// <param name="vs"></param>
        /// <returns></returns>
        public static Stream ToStream(byte[] vs)
        {
            Stream stream = new MemoryStream(vs);
            return stream;
        }
        /// <summary>
        /// Stream写入文件
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="FileName"></param>
        public static void SteramFile(Stream stream, string FileName)
        {
            byte[] vs = new byte[stream.Length];
            stream.Read(vs, 0, vs.Length);
            stream.Seek(0, SeekOrigin.Begin);
            FileStream fileStream = new FileStream(FileName, FileMode.Create);
            BinaryWriter binary = new BinaryWriter(fileStream);
            binary.Write(vs);
            binary.Close();
        }

  

Stream 和 byte[] 之间的转换

上一篇:C#中XmlTextWriter读写xml文件详细介绍


下一篇:leetcode-hard-array-239. Sliding Window Maximum