简体   繁体   English

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

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

I get the following error : 我收到以下错误:

URI formats are not supported. 

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

Edit : 编辑:

在此处输入图片说明

Problem : System.IO.File does not support file downloading from the Internet. 问题: System.IO.File不支持从Internet下载文件。

System.IO.File only Supports the Path of Local Drives System.IO.File仅支持本地驱动器的路径

Solution: You should use WebClient.DownloadFile for Downloading file from Internet URL . 解决方案:您应该使用WebClient.DownloadFile从Internet URL下载文件。

Steps to solve the issue: 解决问题的步骤:

1.Use WebClient.DownloadFile to Download the File into Local Path. 1.使用WebClient.DownloadFile将文件下载到本地路径。
2.Assign the Downloaded Path to IO.File() to Read the Lines from the file. 2.将下载路径分配给IO.File()以从文件读取行。

Step1: Download 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);
           }
        }

Step 2: Access file from IO.File Library 步骤2:IO.File库访问文件

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

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

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