Download file from Internet in Java using apache commons-io

2 years ago Lalit Bhagtani 0

Download file from Internet in Java :-

In this tutorial, we will learn to download file from Internet in java using apache’s commons-io library. Let’s see an implementation using commons-io library with the help of an example :-

Download file from Internet in Java

Apache Commons-IO :- 

In case of commons-io library, we will call copyURLToFile() method of FileUtils class by passing URL and File Object as a parameter. If you don’t have this library in your local setup, then you can download it by using maven or gradle configuration.

Maven :-


Gradle :- 

dependencies {
    compile 'commons-io:commons-io:2.5'

Example :- 


public class DownloadFileFromURL {

  public static void main(String[] args){

    String url = "";
    String file = "D://file.txt";

    try {
       //connectionTimeout, readTimeout = 10 seconds
       FileUtils.copyURLToFile(new URL(url), new File(file), 10000, 10000);

    }catch (IOException e) {


You may also like :- 

  1. Download file from URL in Java using & java.nio

References :- 

  1. Commons IO

That’s all for Download file from Internet in Java, If you liked it, please share your thoughts in comments section and share it with others too.