C#中怎样把流文件转换为字符串
比如我从网上获取了一个网页的源文件,是Stream形式的,现在想要把它转换为字符串形式的,怎么转换啊?...
比如我从网上获取了一个网页的源文件,是Stream形式的,现在想要把它转换为字符串形式的,怎么转换啊?
展开
3个回答
展开全部
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
request.Method = "GET";
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
string SourceCode = readStream.ReadToEnd();
response.Close();
readStream.Close();
SourceCode 就是那个字符串
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
request.Method = "GET";
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
string SourceCode = readStream.ReadToEnd();
response.Close();
readStream.Close();
SourceCode 就是那个字符串
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
System.IO.StreamReader sr = new System.IO.StreamReader(s);
string str=sr.ReadToEnd();//字符串
string str=sr.ReadToEnd();//字符串
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
string aaa = reader.ReadToEnd();
string aaa = reader.ReadToEnd();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询