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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:01:20+00:00 2026-05-30T11:01:20+00:00

The FileInputStream read method has the signature (is that the right term?) – public

  • 0

The FileInputStream read method has the signature (is that the right term?) –

     public int read(byte[] b) throws IOException

     // Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.
     // Returns: the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.

What is the advantage of having a signature like this over something like this –

     public byte[] read(int numberOfBytes) throws IOException
     // Reads up to numberOfBytes bytes of data from this input stream into an array of bytes.
     // Returns- an array of bytes read. Array is empty if there is no more data because the end of the file has been reached.
  • 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-30T11:01:21+00:00Added an answer on May 30, 2026 at 11:01 am

    The first form allows you to reuse the same byte[] array for several executions. Basically you can read the whole stream producing minimal garbage (low GC activity).

    The latter is clearly more convenient but requires creating new instance of byte[] every time it is executed internally within read() method. This means that while reading 10 GiB file (even in 100-byte chunk) your application would allocate 10 GiB of memory in total – not at the same time, but still the garbage collector would work like crazy.

    Have a look at Collection.toArray(T[]) – it follows the same principle.

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

Sidebar

Related Questions

I'm trying to read in file content, ex : public void myMethod(){ FileInputStream fstream
Here's the code: public static void mergeAllFilesJavolution()throws FileNotFoundException, IOException { String fileDir = C:\\TestData\\w12;
I'm using an image component that has a FromBinary method. Wondering how do I
Possible Duplicate: Why does InputStream#read() return an int and not a byte? Issue regarding
I'm attempting to write a method that will read a properties file using Class.getResource(),
sign.verify(signature) returns false in the verifySignature method; and I think it has something to
In Java, this works as expected: public static void testwrite(String filename) throws IOException {
This FileInputStream.available() javadoc says: Returns an estimate of the number of remaining bytes that
I want to write a generic helper method: def using(closeable: [B has close() method],
I've been trying to write some very fast Java code that has to do

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.