c# FileStream、Stream 转 byte[]; byte[]转base64

FileStream继承了Stream

public byte[] ToByte(Stream stream)
        {
            byte[] bytes;
            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);
                bytes = ms.ToArray();
            }
            return bytes;
        }
byte[] ba = ToByte(stream);
string str64 = Encoding.UTF8.GetString(ba);
string ct64 = Convert.ToBase64String(ba);

你可能感兴趣的:(c# FileStream、Stream 转 byte[]; byte[]转base64)