gpt4 book ai didi

c# - 不支持 URL 格式

转载 作者:行者123 更新时间:2023-11-30 13:16:59 26 4
gpt4 key购买 nike

我正在使用 File.OpenRead 方法读取文件,我给出了这个路径

   http://localhost:10001/MyFiles/folder/abc.png

我也试过,但是没有成功

http://localhost:10001//MyFiles//abc.png

但它的给予

URL Formats are not supported

当我像这样给出我的驱动器的物理路径时,它工作正常d:\MyFolder\MyProject\MyFiles\folder\abc.png

如何为 Http 路径提供文件路径?

这是我的代码

public FileStream GetFile(string filename)
{
FileStream file = File.OpenRead(filename);
return file;
}

最佳答案

看看 WebClient ( MSDN docs ),它有很多从网络下载数据的实用方法。

如果您希望资源作为,请尝试:

using(WebClient webClient = new WebClient())
{
using(Stream stream = webClient.OpenRead(uriString))
{
using( StreamReader sr = new StreamReader(stream) )
{
Console.WriteLine(sr.ReadToEnd());
}
}
}

关于c# - 不支持 URL 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17918433/

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