我正在嘗試制作一個簡單的 Minecraft Mod 安裝程式,每當我 DownloadString 是 .jar 的東西并嘗試 DownloadFile 時,它??都會說它的路徑是非法的。有沒有辦法解決它,或者它只是接受 .txt .exe 。
var Mod = wc.DownloadString("Link to download that is .jar");
wc.DownloadFile(Mod, @"C:\Users\" Environment.UserName @"\AppData\Roaming\.minecraft\mods\Mod.jar");
當我使用 .exe 和 .txt 檔案但似乎不適用于 .jar 時,這就是我目前使用的代碼。有什么解決辦法嗎?
uj5u.com熱心網友回復:
方法DownloadFile檔案說
將具有指定 URI 的資源下載到本地檔案。C#
public void DownloadFile (Uri address, string fileName);地址:烏里
指定為字串的 URI,從中下載資料。
檔案名:字串
要接收資料的本地檔案的名稱。
https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=net-6.0
但是在您的示例中,您似乎首先將鏈接下載為字串,然后DownloadFile使用該鏈接而不是原始 Uri 進行呼叫。
即看起來你應該這樣做
wc.DownloadFile("Link to download that is .jar", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft\mods\Mod.jar"));
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/457173.html
標籤:C#
上一篇:從物件串列中的串列中洗掉值
下一篇:位圖影像-減少像素數
