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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:26:44+00:00 2026-06-13T21:26:44+00:00

A file when split to different byte arrays using java, when joined back doesn’t

  • 0

A file when split to different byte arrays using java, when joined back doesn’t get rendered by the file’s application. This happens even when the number of bytes are same on both the original file and rejoined file.

The objective here is to split a large file into different byte arrays and rejoin these byte arrays using a different programming language (C#) over the network.

The code that I have written for splitting is as follows:

File f = new File(fileLoc);
FileInputStream fi = new FileInputStream(f);
int size = fi.available();

int MB2 = 1048576 * 2;
int total = size / MB2;
if (size % MB2 != 0) {
    total += 1;
}
int ch;

while (size > 0) {
    int arraysize;
    if (size < MB2) {
        arraysize = size;
    } else
        arraysize = MB2;
    byte bytes_read[] = new byte[arraysize];
    ch = fi.read(bytes_read, 0, arraysize);
    // The byte_read is added to an array list of byte[]
    // and send along with certain other parameters 
    size = size - ch;
    count++;
}
fi.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-13T21:26:45+00:00Added an answer on June 13, 2026 at 9:26 pm

    You have two problems:

    • you’re using available() as a way to know a file length. that’s not what the method does. available() should almost never be used. I’ve never seen any use-case where using it was a good idea.
    • you’re using the read() method and disregard its returned value. You use it to dcrment the size variable, but you don’t care if you byte array is filled with read bytes or filled with zeroes. read() isn’t guaranteed to read as many bytes as you asked.

    There could be other errors in the way bytes are sent over the wire and read by the other side as well.

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

Sidebar

Related Questions

I am trying to split this css file into different blocks. Everything matching /*@-
I am trying to read file and split its line to get some context(Computer
I want to split a file(suppose a mp3) into four parts.I have tried this
I have text file with some text information and i need to split this
I'm using ImageMagick's convert program to split a pdf file into individual images. It
I am trying to run two different jQuery/Java Scripts under one file name... And
I tried to merge different tab delim files into single file using the following
I have this text file acmst501:57:Runningacmst506:201:Runningacmst506:203:Runningacmst506:209:Runningacmst506:213:Failed which I want to split with delimiters. I
I need to split a file into different ones. Exmaple (original file): *****3123123*****RAW text1
I want to read a file piece by piece. The file is split up

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.