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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:51:42+00:00 2026-06-17T16:51:42+00:00

My java code will not transfer my 25mb file – it will stop at

  • 0

My java code will not transfer my 25mb file – it will stop at 16mb. I have tried changing transferFrom 1 << 24 to 48 & 31 & 8 nothing helped just made it worse. Any idea?

ReadableByteChannel rbc = Channels.newChannel(fileURL.openStream());
FileOutputStream fos = new FileOutputStream(path + fileName);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
  • 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-17T16:51:43+00:00Added an answer on June 17, 2026 at 4:51 pm

    In case you use Java7 you can use the fancy java.nio.file.Files utils to copy.

     URL url = new URL("http://www.stackoverflow.com");
     try (InputStream is = url.openStream()) {
        Files.copy(is, Paths.get("/tmp/output.tmp"));
     }
    

    In case you not, you can use the open source utils- e.g. from Apache (search for FileUtils in Commons IO).

    And in case you want to stick arround with your current solution, you can write it like this:

    BufferedInputStream bis = new BufferedInputStream(url.openStream());
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
        "/tmp/output2.tmp"));
    
    byte[] buffer = new byte[1024 * 1024];
    int read = 0;
    while ((read = bis.read(buffer)) != -1) {
      bos.write(buffer, 0, read);
    }
    bos.close();
    bis.close();
    

    The intention is that you have to read until the end of the stream has been reached. That is why your transferFrom only downloads a limited amount of data as there is no guarantee that all the data will be transferred in one chunk.

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

Sidebar

Related Questions

Is it possible to generate documentation from existing java code which will not have
I have the following Java code which will search in an xml for a
The following java code will not execute. class A{ int sqrt(int a) { }
I wonder a normal java code will show main not found error if it
Is there a built in Java code that will parse a given folder and
Will Java code built and compiled against a 32-bit JDK into 32-bit byte code
I am writing java code. which will work on windows and linux. some code
I heard that JNBridge will translate C# code to native Java code.( I haven't
is there a possible bit of code (php, java, css, html) that will force
I have a java code for SVG drawing. It processes transforms including rotate ,

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.