title: Can't download file from internet using java
body: <p>I'm trying to download file from internet using java but there have a problem. I'm not failed but each time when I'm trying to download it's downloading only 250-300 KB only though the file size is larger than that. I have tried a lot of ways but every time the result is same. </p>
  
  <p>I have tried <strong>Apache Commons IO</strong> like this,</p>
  
  <pre><code>import java.io.File;
  import java.net.URL;
  
  import org.apache.commons.io.FileUtils;
  
  public class Main {
  
      public static void main(String[] args) {
  
          try {
  
              String from = "https://download.gimp.org/mirror/pub/gimp/v2.8/gimp-2.8.10.tar.bz2";
              String to = "/home/ashik/gimp-2.8.10.tar.bz2";
              System.out.println("Starting!");
              FileUtils.copyURLToFile(new URL(from), new File(to), Integer.MAX_VALUE, Integer.MAX_VALUE);
              System.out.println("Finished!");
          } catch (Exception e) {
  
              System.err.println(e.toString());
          }
      }
  }
  </code></pre>
  
  <p>I have tried <strong>Java NIO</strong> like this, </p>
  
  <pre><code>import java.io.FileOutputStream;
  import java.net.URL;
  import java.nio.channels.Channels;
  import java.nio.channels.ReadableByteChannel;
  
  public class Main {
  
      public static void main(String[] args) {
  
          try {
  
              String from = "https://download.gimp.org/mirror/pub/gimp/v2.8/gimp-2.8.10.tar.bz2";
              String to = "/home/ashik/gimp-2.8.10.tar.bz2";
              System.out.println("Starting!");
              ReadableByteChannel rbc = Channels.newChannel(new URL(from).openStream());
              FileOutputStream fos = new FileOutputStream(to);
              fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
              fos.close();
              rbc.close();
              System.out.println("Finished!");
          } catch (Exception e) {
  
              System.err.println(e.toString());
          }
      }
  
  }
  </code></pre>
  
  <p>I have also followed some <strong>stackoverflow</strong> solutions like, <a href="https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java">How to download and save a file from Internet using Java?</a> , <a href="https://stackoverflow.com/questions/25045003/how-to-download-large-sized-files-size-50mb-in-java">How to download large sized Files (size > 50MB) in java</a>, etc but none of them are working. </p>
  
  <p>Every time it's downloading but file size is only 250-300 KB. How to solve this problem?</p>
  
  <p>Platform:</p>
  
  <p>OS: Debian-9</p>
  
  <p>JDK-Version: Oracle JDK-9</p>
  
  <p>IDE: Eclipse Oxygen</p>
  
  <p>Thank you in advance.</p>