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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:49:07+00:00 2026-06-10T23:49:07+00:00

I am struck in this strange problem . I am using the following method

  • 0

I am struck in this strange problem .

I am using the following method to download files :

public boolean downloadSection(String link,String fileLocation,long currentlyDownloadedBytes){

     try {

                RandomAccessFile file = new RandomAccessFile(fileLocation, "rw");
                file.seek(currentlyDownloadedBytes+1);

                URL imageUrl = new URL(link);
                HttpURLConnection conn  =(HttpURLConnection)imageUrl.openConnection();
                conn.setRequestProperty("Range", "bytes=" + currentlyDownloadedBytes + "-");
                conn.setConnectTimeout(100000);
                conn.setReadTimeout(100000);
                conn.setInstanceFollowRedirects(true);

                InputStream is=conn.getInputStream();
                byte buffer[]=new byte[1024];;
                while (true) {
                    // Read from the server into the buffer
                    int read = is.read(buffer);
                    if (read == -1) {
                        break;
                    }
                   // Write buffer to file
                    file.write(buffer, 0, read);
                 }

                file.close();
                return true;
                } catch (Exception ex){
                      ex.printStackTrace();
                      return false;
                      }

 } 

When i download mp3 file using this code the downloades file opens up well , But a downloaded android app(.apk file) gives Package Parsing Error on opening and an image never opens up .

Please help
Thank you

  • 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-10T23:49:09+00:00Added an answer on June 10, 2026 at 11:49 pm

    Several things look strange:

    a) It looks like you added manually the signature of the method for this question (because link doesn’t have a type, so it won’t even compile).

    b) There are two variables/parameters – alreadyDownloadedBytes and currentlyDownloadedBytes. I assumed it’s caused by #a

    c) You are doing following

    file.seek(currentlyDownloadedBytes+1);
    

    and you should instead do this

    file.seek(currentlyDownloadedBytes);
    

    The reason is because you seek to offset. So, as example, if you read just 1 byte, you have to seek to offset 1 (which would be the second byte in file).

    d) Check whether any exception are thrown and caught.

    e) Where do you update currentlyDownloadedBytes or alreadyDownloadedBytes?

    f) My final recommendation would be to debug your application and make sure that the whole file is downloaded

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

Sidebar

Related Questions

I have a strange problem with a calculator made using boost::spirit. This calculator is
Temporary ASP.NET Files Missing I struck with this error at yesterday itself. I googled
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
This may sound simple but i am stuck up at a very strange problem.
I've run into a strange problem. The following simplified code reproduces the problem in
I have a strange problem in C about including header files. main.c #include <stdio.h>
I seem to have a strange problem: I coded an application in C++ (using
I'm facing a strange problem (which is connected to this problem ) regarding different
This struck me as really weird behaviour and I spent a while checking for
Im stuck with this little project in C# but basically my problem is this:

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.