Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

join the multiple file parts into single one (same file split before) using java

I have a code, here, for splitting file into required size of chunks i.e. 50~100KB. Now I want to join these parts back to the same file. I have written a code to do that, and able to join all parts somehow but, I think, lost the meta info because mp3 file is not playing in mediaplayer.
    package fileioapp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;

/**
 *
 * @author Saqib Ali Rana
 */
public class fileMergeProgram {


    public static void main(String[] args) throws FileNotFoundException, IOException {
    String file_name ="song_0.mp3";
    File file = new File(file_name);
    int file_counter=0;
    File originFile = new File("song.mp3");
    int buff_size = (int) originFile.length();
    byte []readinBuff = new byte[buff_size];
    FileInputStream fIn = new FileInputStream(file);
    FileOutputStream fout = new FileOutputStream("song_merge.mp3");
    int file_parts =25;
    int offset=0;
    int i=1;
    int length=(int) file.length();
   // int length = 1024*100;
    while(file_parts<0){

        fIn.read(readinBuff,offset,length);// keep reading into this buffer until all parts ends     
        offset+=length;

        file_parts--;
        fIn.close();
        file_name="song_"+i+".mp3";
        File file2 = new File(file_name);//next file
        fIn = new FileInputStream(file2);
        if(file2.exists()){
            length = (int) file2.length();
             continue;
        }else{
             break;

        }



    }//end while loop
    fout.write(readinBuff);
    fout.close();


 }//end main method


}

Comments