星空网 > 软件开发 > ASP.net

Stream(流)的基本操作

//把流转化为文件 
public static void StreamToFile(Stream stream, string filepath) { byte[] bytes = StreamToBytes(stream); FileStream fileStream = new FileStream(filepath, FileMode.Create); fileStream.Write(bytes, 0, bytes.Length); fileStream.Flush(); fileStream.Close(); }
//把流转化为字节数组 public static byte[] StreamToBytes(Stream stream) { MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return memoryStream.ToArray(); }
//把流转化为Base64字符串
public static string StreamToString(Stream stream) { byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); string base64string = Convert.ToBase64String(buffer); return base64string; }
//把Base64字符串转化为流
    pubblic static Stream StringToStream(string str)
    {
       byte[] bt = Convert.FromBase64String(str);
            System.IO.MemoryStream stream = new System.IO.MemoryStream(bt);
    }

求补充。。。。。。。。。。。。。。

 




原标题:Stream(流)的基本操作

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流