streamreader readline
时间: 2023-09-29 17:04:06 浏览: 166
StreamReader的ReadLine()方法用于从文本流中读取一行数据。该方法会读取数据流中当前行的数据,并将其作为一个字符串返回。可以通过循环调用ReadLine()方法来逐行读取文本流中的数据,直到遇到数据流的结尾,此时返回null。以下是一个使用StreamReader的ReadLine()方法的例子:
```csharp
using (StreamReader sr = new StreamReader("file.txt"))
{
string line = sr.ReadLine();
while (line != null)
{
Console.WriteLine(line);
line = sr.ReadLine();
}
}
```
上述代码会打开名为“file.txt”的文件,并逐行读取其中的数据,并将每行数据输出到控制台。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [C#处理文本文件TXT实例详解](https://download.csdn.net/download/weixin_38609453/13992816)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [C#的StreamReader类使用说明](https://blog.csdn.net/u010033786/article/details/127036362)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [StreamReader类以及其方法ReadLine,Read,ReadToEnd的分析](https://blog.csdn.net/kaituozhe345/article/details/7334988)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文