title: Download binary file from Github using Java
body: <p>I'm trying to download this file (<a href="http://github.com/downloads/TheHolyWaffle/ChampionHelper/ChampionHelper-4.jar" rel="noreferrer">http://github.com/downloads/TheHolyWaffle/ChampionHelper/ChampionHelper-4.jar</a>) with the following method and it doesn't seem to work. I'm getting an empty/corrupt file.</p>
  
  <pre><code>String link = "http://github.com/downloads/TheHolyWaffle/ChampionHelper/ChampionHelper-4.jar";
  String fileName = "ChampionHelper-4.jar";
  
  URL url = new URL(link);
  URLConnection c = url.openConnection();
  c.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 1.2.30703)");
  
  InputStream input;
  input = c.getInputStream();
  byte[] buffer = new byte[4096];
  int n = -1;
  
  OutputStream output = new FileOutputStream(new File(fileName));
  while ((n = input.read(buffer)) != -1) {
      if (n &gt; 0) {
          output.write(buffer, 0, n);
      }
  }
  output.close();
  </code></pre>
  
  <p>But I can successfully download the following file from my dropbox (<a href="https://dl.dropbox.com/u/13226123/ChampionHelper-4.jar" rel="noreferrer">http://dl.dropbox.com/u/13226123/ChampionHelper-4.jar</a>) with the same method. </p>
  
  <p>So somehow Github knows that I'm not a regular user trying to download a file. I already tried to change the user agent, but that didn't help either.</p>
  
  <p>So how should I download a file that is hosted on my Github account using Java?</p>
  
  <p>EDIT: I tried to use the apache commons-io for this but I get the same effect, an empty/corrupt file.</p>