Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
File Download Manager System in Java
Next article icon

File Download Manager System in Java

Last Updated : 10 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A file download manager system allows us to download files from the internet to a local directory. This system can handle multiple downloads, improve download speed, and also manage the download process in a structured way.

In this article, we will build a file download manager system in Java using multiple classes, interfaces, and threads to handle the downloads concurrently. This project will help beginners understand Java programming concepts like multithreading, input/output operations, and URL handling.

Working of the File Download Manager System

Here is how our download manager system is going to work:

  • The user provides a list of file URLs to download.
  • Each download task will be processed concurrently using multiple threads.
  • The system will check if the URL is valid before initiating the download.
  • The file will be downloaded to the specified directory.
  • The system will report the success or failure of each download.

Project Structure

The image below demonstrates the project structure

ProjectStructure


We will organize the code into these parts which are listed below:

  • DownloadTask: This class implements the callable interface to represent a download task.
  • DownloadUtils: This class provides utility methods for validating URLs, downloading files, and verifying directories.
  • DownloadManager: This class manages the execution of multiple download tasks concurrently.
  • Main: This class is the entry point to initiate the download process.

Let's now try to implement the code.

Java File Download Manager System Project Implementation

1. DownloadTask Class

This class is used to represents an individual download task and also handles the actual file downloading process. It implements the Callable interface to allow execution of tasks using threads. This class is also responsible for handling the download logic for each file, such as starting the download, simulating download progress, and returning the status of the download.

DownloadTask.java:

Java
package com.downloader;  import java.util.concurrent.Callable;  public class DownloadTask implements Callable<String> {     private String fileUrl;     private String destination;      public DownloadTask(String fileUrl, String destination) {         this.fileUrl = fileUrl;         this.destination = destination;     }      @Override     public String call() throws Exception {         System.out.println("Starting download from: " + fileUrl);         try {             Thread.sleep(3000); // Simulating download time         } catch (InterruptedException e) {             Thread.currentThread().interrupt();             return "Download interrupted for " + fileUrl;         }         System.out.println("Download completed for: " + fileUrl);         return "Download successful for " + fileUrl;     } } 


2. DownloadUtils Class

This class is a utility class that provides various helper methods used in the file download process. This class handles URL validation, file downloading, and directory verification.

DownloadUtils.java:

Java
package com.downloader;  import java.io.*; import java.net.*; import java.nio.file.*;  public class DownloadUtils {      /**      * Validates the given URL to check if it's a valid and accessible URL.      *      * @param urlString The URL to validate.      * @return true if the URL is valid, false otherwise.      */     public static boolean isValidUrl(String urlString) {         try {             URL url = new URL(urlString);             HttpURLConnection connection = (HttpURLConnection) url.openConnection();             connection.setRequestMethod("HEAD"); // Only check the headers (no body)             connection.setConnectTimeout(5000); // Set timeout to 5 seconds             connection.setReadTimeout(5000);             int responseCode = connection.getResponseCode();             return (responseCode == HttpURLConnection.HTTP_OK);         } catch (MalformedURLException e) {             System.err.println("Invalid URL: " + urlString);             return false;         } catch (IOException e) {             System.err.println("Error checking URL: " + e.getMessage());             return false;         }     }      /**      * Downloads a file from a URL and saves it to the specified destination.      *      * @param fileUrl      The URL of the file to download.      * @param destination  The file path to save the downloaded file.      * @throws IOException if an I/O error occurs during downloading.      */     public static void downloadFile(String fileUrl, String destination) throws IOException {         URL url = new URL(fileUrl);         HttpURLConnection connection = (HttpURLConnection) url.openConnection();         connection.setRequestMethod("GET");         connection.setConnectTimeout(5000); // Set timeout to 5 seconds         connection.setReadTimeout(5000);          try (InputStream in = connection.getInputStream();              FileOutputStream out = new FileOutputStream(destination)) {              byte[] buffer = new byte[4096];             int bytesRead;             while ((bytesRead = in.read(buffer)) != -1) {                 out.write(buffer, 0, bytesRead);             }         }          System.out.println("File downloaded to: " + destination);     }      /**      * Verifies if the destination directory exists. If it doesn't, it creates the directory.      *      * @param directoryPath The path to the directory.      * @return true if the directory exists or was successfully created, false otherwise.      */     public static boolean verifyDirectory(String directoryPath) {         Path path = Paths.get(directoryPath);         if (!Files.exists(path)) {             try {                 Files.createDirectories(path);                 System.out.println("Directory created: " + directoryPath);                 return true;             } catch (IOException e) {                 System.err.println("Failed to create directory: " + e.getMessage());                 return false;             }         }         return true;     } } 


3. DownloadManager Class

This class is the heart of the download manager system. It is responsible for managing multiple concurrent download tasks and executing them in parallel using a fixed thread pool.

DownloadManager.java:

Java
package com.downloader;  import java.util.concurrent.*; import java.util.*;  public class DownloadManager {      private static final int NUM_THREADS = 4;     private ExecutorService executorService;      public DownloadManager() {         executorService = Executors.newFixedThreadPool(NUM_THREADS);     }      public void startDownload(String[] fileUrls, String destination) {         List<Callable<String>> tasks = new ArrayList<>();         for (String fileUrl : fileUrls) {             tasks.add(new DownloadTask(fileUrl, destination));         }          try {             List<Future<String>> results = executorService.invokeAll(tasks);             for (Future<String> result : results) {                 try {                     System.out.println(result.get());                 } catch (ExecutionException | InterruptedException e) {                     e.printStackTrace();                 }             }         } catch (InterruptedException e) {             e.printStackTrace();         } finally {             executorService.shutdown();         }     }      public static void main(String[] args) {         String[] fileUrls = {                 "http://example.com/file1.zip",                 "http://example.com/file2.zip",                 "http://example.com/file3.zip",                 "http://example.com/file4.zip"         };          String destination = "/path/to/save/files";          DownloadManager downloadManager = new DownloadManager();         downloadManager.startDownload(fileUrls, destination);     } } 

Output:

Output


How to Run the Project in IntelliJ IDEA?

To run the project on IntelliJ IDEA, follow these steps:

  • Open IntelliJ IDEA and create a new Java project.
  • Create the following package structure:
    • com.downloader
  • Add the classes (DownloadTask, DownloadUtils, DownloadManager, Main) under this package.
  • Save all files.
  • Run the DownloadManager class.
Running-the-project

Next Article
File Download Manager System in Java

M

musklf2s
Improve
Article Tags :
  • Java
  • Java Projects
Practice Tags :
  • Java

Similar Reads

    Working with JAR and Manifest Files In Java
    A Jar file stands for Java archives, it is a compressed archive that contains the Java classes, libraries, metadata, and other files such as media data, audio, video, and documents. When we want to distribute a version of the software or distribute a single file, and not a directory structure filled
    6 min read
    File canRead() method in Java with Examples
    The canRead()function is a part of the File class in Java. This function determines whether the program can read the file denoted by the abstract pathname. The function returns true if the abstract file path exists and the application is allowed to read the file.Function signature: public boolean ca
    2 min read
    Redirecting System.out.println() Output to a File in Java
    System.out.println()  is used mostly to print messages to the console. However very few of us are actually aware of its working mechanism. We can use System.out.println() to print messages to other sources too, not just restricting it to the console. However, before doing so, we must reassign the st
    2 min read
    What is Memory-Mapped File in Java?
    Memory-mapped files are casual special files in Java that help to access content directly from memory. Java Programming supports memory-mapped files with java.nio package. Memory-mapped I/O uses the filesystem to establish a virtual memory mapping from the user directly to the filesystem pages. It c
    4 min read
    Runtime JAR File in Java
    JAR stands for Java Archive file. It is a platform-independent file format that allows bundling and packaging all files associated with java application, class files, audio, and image files as well. These files are needed when we run an applet program. It bundles JAR files use a Data compression alg
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences