首页 > 解决方案 > 无法在 C# 程序中下载 JDK

问题描述

我正在尝试编写一个需要jdk在机器上下载的 C# 程序。我写了一些代码,但每次只能下载 3-4 kb

static void Main(string[] args)
{
    WebClient client = new WebClient();
    string address = "https://download.oracle.com/otn/java/jdk/8u211-b12/478a62b7d4e34b78b671c754eaaf38ab/jdk-8u211-windows-x64.exe";
    Uri uri = new Uri(address);
    var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    string fileName = desktop + "\\jdk.exe";
    Console.WriteLine("Downloading file");
    client.DownloadFile(address, fileName);
    Console.WriteLine("Done Downloading File");
    Console.ReadLine();

}

标签: c#

解决方案


如果你把地址放在浏览器中,你很快就会明白为什么。

下载 JDK8 需要您现在登录。他们为旧版本的 Java 执行此操作。我相信 JDK8 大约在一个月前开始了这种行为。


推荐阅读