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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:54:25+00:00 2026-06-07T04:54:25+00:00

Please have a look at the following code package normal; import java.io.*; import java.util.*;

  • 0

Please have a look at the following code

package normal;

import java.io.*;
import java.util.*;

public class ReGenerateFiles
{
    private File inputFolder, outputFolder;
    private String outputFormat, nameOfTheFile;

    private FileInputStream fis;
    private FileOutputStream fos;
    List <Byte> al;

    private byte[] buffer;

    private int blockNumber = 1;

    public ReGenerateFiles(File inputFile, File outputFile, String nameOfTheFile, String outputFormat)
    {
        this.inputFolder = inputFile;
        this.outputFolder = outputFile;
        this.nameOfTheFile = nameOfTheFile;
        this.outputFormat = outputFormat;
    }

    public void reGenerate() throws IOException
    {
        File file[] = inputFolder.listFiles();

        for(int i=0;i<file.length;i++)
        {
            System.out.println(file[i]);
        }

        for(int i=0;i<file.length;i++)
        {
            try
            {
                buffer = new byte[5000000];


                int read = fis.read(buffer, 0, buffer.length);
                fis.close();

                writeBlock();


            }
            catch(IOException io)
            {
                io.printStackTrace();
            }
            finally
            {
                fis.close();
                fos.close();
            }
        }
    }

    private void writeBlock()throws IOException
    {
        try
        {
            fos = new FileOutputStream(outputFolder+"/"+nameOfTheFile+"."+outputFormat,true);
                fos.write(buffer, 0, buffer.length);
                fos.flush();
                fos.close();
        }
        catch(Exception e)
        {
            fos.close();
            e.printStackTrace();
        }
        finally
        {
            fos.close();
        }
    }


}

In here, I am trying to re-assemble a splited file, back to its original file. This is how I split it (The selected answer)

Now, when I am trying to re-assemble it, I am getting an error saying something similar to “Cannot access kalimba.mp3. It is used by another program”. This happens after executing 93 splitted files (there are 200 more). Why it is happening, even though I have make sure the streams are closed inside finally block?

Another question, I have assigned 500000 as the byte array value. I did this because I failed to set the byte array according to the original size of the particular file which is about to process. I assigned the byte array value as

buffer = new byte[(byte)file[i].length();

before, but it didn’t work.

Please help me to solve these two issues and re-assemble the splitted file back, correctly.

  • 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-07T04:54:27+00:00Added an answer on June 7, 2026 at 4:54 am

    That is because the buffer never fitted to the size of the actual content. It is always 50000, and the actually size vary. Thats the issue

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

Sidebar

Related Questions

please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
Please have a look the following code import javax.swing.*; import java.awt.event.*; import java.awt.*; public
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout;
Please have a look at the following code. import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.*;
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue;
Please have a look at the following code import java.awt.event.*; import javax.swing.*; import java.awt.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code of JavaFX and CSS. Login2.java package

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.