繁体   English   中英

读取所有行时不支持URI格式

[英]URI formats are not supported when reading all lines

我收到以下错误:

URI formats are not supported. 

    string path = @"http://...../xml/en/df.js";
    String[] allLines = System.IO.File.ReadAllLines(path);

编辑:

在此处输入图片说明

问题: System.IO.File不支持从Internet下载文件。

System.IO.File仅支持本地驱动器的路径

解决方案:您应该使用WebClient.DownloadFile从Internet URL下载文件。

解决问题的步骤:

1.使用WebClient.DownloadFile将文件下载到本地路径。
2.将下载路径分配给IO.File()以从文件读取行。

步骤1:下载文件。

     String source="http://mypath/path2/myfile.js";
     String destination=@"c:\myfile.js";

        void DownloadMyFile()
        {
           using (WebClient webClient = new WebClient())
           {
               webClient.DownloadFile(source,destination);
           }
        }

步骤2:IO.File库访问文件

String[] allLines =System.IO.File.ReadAllLines(destination);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM