如何在此代碼中將流輸出附加到字符串而不是文件?流到字符串
HttpWebResponse res = (HttpWebResponse)httpRequest.GetResponse();
using (Stream output = File.OpenWrite(@"c:\temp\tmp.html"))
using (Stream input = res.GetResponseStream())
{
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
input.Close();
output.Close();
}
OK,工作。謝謝!之後我應該使用Dispose()來清除Streamreader,對吧? – Rado
@Rado是的,你應該。但是我的回答已經將它封裝在'using'語句中,它將爲您調用Dispose。 –
哦,是的,我現在記得。感謝提醒... – Rado