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 8719753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:52:24+00:00 2026-06-13T06:52:24+00:00

I am learning Java OOP. My program downloads file via FTP. I want to

  • 0

I am learning Java OOP. My program downloads file via FTP. I want to resume downloading when it is started again. Here is my code :

URL urlName = new URL(url);
URLConnection con = urlName.openConnection();
BufferedInputStream in = new BufferedInputStream(con.getInputStream());

int i = 0;
long downloadedSizeKB;
System.out.println("before skip");
long k = in.skip(counter);
System.out.println(k);
byte[] bytesIn = new byte[1024];
while ((i = in.read(bytesIn)) >= 0) {
    if(counter >= alreadyDownloadedBytes) {
        out.write(bytesIn, 0, i);
        downloadedSizeKB = counter/1024;
        downSize.setText(downloadedSizeKB + " KB downloaded...");

        while(isPaused) {
            downSize.setText(downloadedSizeKB + " KB PAUSED");
            Thread.sleep(1000);                     
        }
    }
    counter += i;
}

in.close();

At first I’ve tried reading it as much as the lenght of previously downloaded file and then resume reading and writing from that point. Reading file before resuming downloading takes too much time (1-2 minutes for like 100MB). After that I realized there is a skip method but I guess it does the same thing since it takes nearly same amount of time.

Is there faster way to start reading a file from a specific byte of it? Or should I do this some another way? Or this is the only way?

  • 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-06-13T06:52:26+00:00Added an answer on June 13, 2026 at 6:52 am

    You can use apache.commons.net.ftp.FTPClient (is in commons-net.jar library).

    You have methods as: setRestartOffset(yourOffset), using it before retrieve the file, the file data will start from the specified offset.

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

Sidebar

Related Questions

I'm just learning java and following a book. I have a program written via
I just started learning java and I'm working on a program. I'm getting an
I am quite a newbie in OOP using java and I'm learning as I
I'm learning Java on my own; and therefore the code below has no function
I'm learning Java and OOP, and have been doing the problems at Project Euler
I am learning java. Now, it is always a practice in oop to make
I've downloaded the JAVA Eclipse IDE and started learning Java. I have a good
I have started learning Java language for Android Application developement. As per my understanding
I'm learning Java here and trying to get to grips with classes and how
I've recently starting learning java web development and I want to learn/understand: What constitutes

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.