zoukankan      html  css  js  c++  java
  • 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);
        }

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

  • 相关阅读:
    磁盘相关命令
    shell $用法
    setuid setgid stick bit 特殊权限 粘滞位
    运维面试题2
    mysql 外键约束
    创建MySQL 用户
    shell 脚本定时创建月份表
    apache 配置多个虚拟主机,不同的端口
    sublime3中文乱码解决包ConvertToUTF8.zip
    yii2安装
  • 原文地址:https://www.cnblogs.com/gaocong/p/4935542.html
Copyright © 2011-2022 走看看