Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:48:29+00:00 2026-05-31T23:48:29+00:00

I started creating file downloader class. Here is what i have: public class Downloader

  • 0

I started creating file downloader class. Here is what i have:

public class Downloader {

    //download url
    URL url;

    public Downloader(URL downloadURL){
        url = downloadURL;
    }


      public void toFile(File fName) {
            try {

                HttpURLConnection urlConnection = (HttpURLConnection) url
                        .openConnection();

                urlConnection.setRequestMethod("GET");
                urlConnection.setDoOutput(true);

                urlConnection.connect();

                FileOutputStream fileOutput = new FileOutputStream(fName);

                InputStream inputStream = urlConnection.getInputStream();

                byte[] buffer = new byte[1024];
                int bufferLength = 0;

                while ((bufferLength = inputStream.read(buffer)) > 0) {
                    fileOutput.write(buffer, 0, bufferLength);

                }

                fileOutput.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }




}

I need to call this downloader in new thread. Maybe someone could give me hint why i need to call new thread or asyc task for this.

public void downloadFile(String urlToDownload,String path) throws MalformedURLException{




        new Thread(new Runnable() {
            public void run() {
                new Downloader(new URL(urlToDownload)).toFile(new File(path));

                 }


          }).start();
}

So when i want to downlaod my file it’s strating downloading asynchronical.

I don’t really want that.
I want to create downloader where i could choose if i want synchronously or async download a file.

But in the first place, i want to know when file was downloaded. How could i know this ?

Maybe someone had done this and could help me.
I need to know when file is downloaded.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:48:30+00:00Added an answer on May 31, 2026 at 11:48 pm
    1. You can’t download anything on the main thread, you get an Application Not Responding dialog in versions < 3.0, and in 3.0 and higher simply get an exception.

    2. Your current approach is nearly right.

    3. If you want to publish progress of downloading and notify UI about the finished downloading you can use AsyncTask, Handler or Intent to notify any application component about the finished downloading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have not started creating the code so I don't have anything to show,
I have started creating a game, and I added a second project, it's the
I have recently started creating an iPhone application using Appcelerator's Titanium. Since the application
I have finally started messing around with creating some apps that work with RESTful
I have a class 'Downloader' derived from QObject that runs in a worker thread.
I have following problem. I use this tutorial to creating a multiple file uploader:
I've just started creating Unit Tests for my code again. I have had PHPUnit
I have started creating small applications in Java using Net-beans, i was trying to
Right so, I started my project on creating a Java download manager which is
i started creating application only using dpr file in delphi 2009 , i think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.