title: Download file using java apache commons?
body: <p>How can I use the library to download a file and print out bytes saved? I tried using </p>
  
  <pre><code>import static org.apache.commons.io.FileUtils.copyURLToFile;
  public static void Download() {
  
          URL dl = null;
          File fl = null;
          try {
              fl = new File(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip");
              dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
              copyURLToFile(dl, fl);
          } catch (Exception e) {
              System.out.println(e);
          }
      }
  </code></pre>
  
  <p>but I cannot display bytes or a progress bar.  Which method should I use?</p>
  
  <pre><code>public class download {
      public static void Download() {
          URL dl = null;
          File fl = null;
          String x = null;
          try {
              fl = new File(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip");
              dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
              OutputStream os = new FileOutputStream(fl);
              InputStream is = dl.openStream();
              CountingOutputStream count = new CountingOutputStream(os);
              dl.openConnection().getHeaderField("Content-Length");
              IOUtils.copy(is, os);//begin transfer
  
              os.close();//close streams
              is.close();//^
          } catch (Exception e) {
              System.out.println(e);
          }
      }
  </code></pre>