简体   繁体   中英

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 only Supports the Path of Local Drives

Solution: You should use WebClient.DownloadFile for Downloading file from Internet URL .

Steps to solve the issue:

1.Use WebClient.DownloadFile to Download the File into Local Path.
2.Assign the Downloaded Path to IO.File() to Read the Lines from the file.

Step1: Download File.

     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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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