gpt4 book ai didi

c# - 我无法使用 c# 的 StreamReader 类从 .txt 文件中读取内容

转载 作者:太空宇宙 更新时间:2023-11-03 20:55:26 24 4
gpt4 key购买 nike

这是我的代码..我正在尝试从存储在 music 文件夹中的 .txt 文件中读取数据。但是我收到一些错误,例如,System.NotSupportedException。不支持给定路径的格式。

请帮忙……

string path = @"Music:\streamfile.txt";

using (StreamReader sr = File.OpenText(path))
{
String s = "";

while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
Console.ReadLine();

最佳答案

某处有一个包含“特殊”文件夹的列表,但您可以自己构建它:

  string path = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"),
"Music", "streamfile.txt");

关于c# - 我无法使用 c# 的 StreamReader 类从 .txt 文件中读取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51099076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com