【发布时间】:2017-02-10 09:28:28
【问题描述】:
我为 Python 找到了 this answer。是否适用于 C# WebClient.OpenRead?
在以下示例中:
- OpenRead 是否一次下载所有 csv 文件(因此 ReadLine 指的是 本地 流)?
- 与 Python 中一样,下载是通过连续的 ReadLine 逐步完成的吗?
代码示例
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://www.MyWebsite.com/FileToDownload.csv");
StreamReader csvFile= new StreamReader(stream);
while (!csvFile.EndOfStream)
{
string line = csvFile.ReadLine();
//do stuff with line
}
【问题讨论】:
-
你不是说
new StreamReader(stream)吗? -
看source code,好像回复一下子就下载好了,虽然我也不是很确定(所以只能评论)。
-
您询问的是 OpenRead 和 csv 文件,而您的 StreamReader 使用的是 csv 文件而不是 WebClient。您能否再次查看您的问题?
-
我的错。我已经更正了代码示例。