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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:09:49+00:00 2026-06-18T12:09:49+00:00

The following code reads data from a file using a BufferedInputStream and processes it

  • 0

The following code reads data from a file using a BufferedInputStream and processes it in chuncks. I would like to modify this code so that instead of the data coming from a file through a stream, I would like to have it come from a byte array. I have already read the file’s data into a byte array and I want to use this while…loop to process the array data instead of working with the data from the file stream. Not sure how to do it:

FileInputStream in = new FileInputStream(inputFile);
BufferedInputStream origin = new BufferedInputStream(in, BUFFER);

int count;

while ((count = origin.read(data, 0, BUFFER)) != -1)
{
  // Do something
}
  • 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-18T12:09:50+00:00Added an answer on June 18, 2026 at 12:09 pm

    You can use a ByteArrayInputStream to wrap your existing byte array into an InputStream so that you can read from the byte array as from any other InputStream:

    byte[] buffer = {1,2,3,4,5};
    InputStream is = new ByteArrayInputStream(buffer);
    
    byte[] chunk = new byte[2];
    while(is.available() > 0) {
        int count = is.read(chunk);
        if (count == chunk.length) {
            System.out.println(Arrays.toString(chunk));
        } else {
            byte[] rest = new byte[count];
            System.arraycopy(chunk, 0, rest, 0, count);
            System.out.println(Arrays.toString(rest));
        } 
    }
    
    Output:
    [1, 2]
    [3, 4]
    [5]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of Java code that reads strings from CSV file.
i use the following code for downloading a file from the internet. using this
I'm using the following code to read data from an XML file stored in
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
I have the following code that read input from txt file as follow Paris,Juli,5,3,6
program reads the following data from a .txt file: f 3.40 f 4.00 m
I have a timer that loops through following code every second. this code reads
I have got the following code from here to read an Excel file using
I have an application written in VB.NET that reads data from a file and
I'm working on a program for class that reads data from a file, the

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.