title: Downloading a file from a URL -- Nothing works
body: <p>I run a Minecraft server for my friends, and a while back I very shoddily put together an installer which would download mods and install them properly to the correct location.</p>
  
  <p>After about 6 hours of figuring out how to do what I was trying to do, I successfully got a working installer. I tried it again today, and found that it has stopped working. I've been trying to fix it, but to no avail. I cannot find any solution which actually gets the whole file to download, rather, an empty 4KB file is created. I tried on a different computer and the same thing happened. I'm running the latest version of Java.</p>
  
  <p>This is the method I'm using to download the file. I have tried solutions using a <code>ReadableByteChannel</code>, but that yielded similar results, with a 1KB empty file.</p>
  
  <pre><code>    public void download(String filename, URL url) {
      try {
          String fileName = filename; 
          URL link = url;
  
          InputStream in = new BufferedInputStream(link.openStream());
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          byte[] buf = new byte[1024];
          int n = 0;
          StringBuffer stringBuffer = new StringBuffer();
          while (-1 != (n = in.read(buf))) {
              out.write(buf, 0, n);
          }
          out.close();
          in.close();
          byte[] response = out.toByteArray();
  
          FileOutputStream fos = new FileOutputStream(fileName);
          fos.write(response);
          fos.close();
  
          System.out.println("Download complete!");
      } catch (Exception e) {
          System.out.println("Download failed, something went wrong!");
      }
  }
  </code></pre>
  
  <p>Is there something wrong with the method above? I can't really wrap my head around how downloading the file works, else I'd troubleshoot it myself. Any methods I can find on Google are going about it in pretty much the same way. </p>
  
  <pre><code>Printing stack trace:
  at Install.download(Install.java:93)
  at Install.downloadFile(Install.java:41)
  at Install.main(Install.java:106)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  </code></pre>
  
  <p><strong>EDIT:</strong> Problem solved, used a different file hosting site to host the file. Now I just need to figure out how I can update the file without changing the URL.</p>