c#操作方法

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#操作方法

上一篇:vim2020最强 windows配置


下一篇:C# 0-1背包问题