簡體   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