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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:56:53+00:00 2026-06-07T07:56:53+00:00

I would like to know the difference in terms of performance between these two

  • 0

I would like to know the difference in terms of performance between these two blocks that try to send a big file over a TCP socket.
I couldn’t find much resources explaining their efficiency.

A-

byte[] buffer = new byte[1024];
int number;

while ((number = fileInputStream.read(buffer)) != -1) {
socketOutputStream.write(buffer, 0, number);
}

B-

byte mybytearray = new byte[filesize];
os.write(mybytearray);

Which one is better in terms of transfer delay?

Also What is the difference if i set the size to 1024 or 65536? How would that affect the performance.

  • 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-07T07:56:55+00:00Added an answer on June 7, 2026 at 7:56 am

    The latency until the last byte of the file arrives is basically identical. However the first one is preferable, although with a much larger buffer, for the following reasons:

    1. The data starts arriving sooner.
    2. There is no assumption that the file size fits into an int.
    3. There is no assumption that the entire file fits into memory, so
    4. It scales to very large files without code changes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know is there any difference in performance between these two
I would like to know what is the difference between those two categories that
I would like to know what the difference between these instructions is: MOV AX,
I would like to know if there is a difference in terms of performance
I would like to know difference between static variables and global variables in terms
I would like to know the difference between the 2 methods in terms of
I would like to know what is the difference between Sleep mode and Deep
I would like to know if there is a difference in speed between computing
I would like to know what is the exact difference between a class snippet
I would like to know the difference and additional features in Antennahouse over Apache

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.