c#操作方法

2020-12-19 15:35

阅读:772

标签:string   bre   response   ade   方法   bsp   http   new   ati   

1、通过读取路径将文件转为byte[]

    

  //将一个file文件转化为byte[]
        public static byte[] GetBytesFromUrl1(string url)
        {
            byte[] b;
            FileWebRequest myReq = (FileWebRequest)WebRequest.Create(url);
            WebResponse myResp = myReq.GetResponse();
            Stream stream = myResp.GetResponseStream();
            //int i;
            using (BinaryReader br = new BinaryReader(stream))
            {
                b = br.ReadBytes(1000000);
                br.Close();
            }
            myResp.Close();
            return b;
        }

 

    //通过Url地址将文件转成byte[]
        public static byte[] GetBytesFromUrl(string url)
        {
            byte[] b;
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
            WebResponse myResp = myReq.GetResponse();
            Stream stream = myResp.GetResponseStream();
            //int i;
            using (BinaryReader br = new BinaryReader(stream))
            {
                b = br.ReadBytes(500000);
                br.Close();
            }
            myResp.Close();
            return b;
        }

 

c#操作方法

标签:string   bre   response   ade   方法   bsp   http   new   ati   

原文地址:https://www.cnblogs.com/wenghan/p/13896167.html


评论


亲,登录后才可以留言!