Q:

How to split a file in java into multiple same size parts using bytestream

The following is the code I have tried. I am able to read 100KB of files 
song.mp3(total size is 2.4MB), but not able to read subsequent chunks (100KB) 
in the loop. The loop only creates the file song_0.mp3 and it's empty.
I need to create files as song_0.mp3, song_1.mp3,... 
public class fileIOwrite2multiplefiles {
        public static void main(String[] args) throws IOException{
        // TODO code application logic here

        File file = new File("song.mp3");

        FileInputStream fIn = new FileInputStream("song.mp3");
        FileOutputStream fOut = new FileOutputStream("song_0.mp3");
        int chunk_size = 1024*100;
        byte[] buff = new byte[chunk_size]; // 100KB file 

        while(fIn.read()!=-1){

          fIn.read(buff);
          String file_name =file.getName();
          int i=1;
          int total_read=0;
          total_read +=chunk_size;
          long read_next_chunk= total_read;
          String file_name_new = file_name+"_"+ i +".mp3";
          File file_new = new File(file_name);
          i++;
          fOut = new FileOutputStream(file_name_new);
          fOut.write(buff);
          buff = null;
          fIn.skip(total_read);// skip the total read part

       }//end of while loop      

        fIn.close();
        fOut.close();          
    }
}

A:

You can rewrite your main method as :
public static void main(String[] args) throws IOException {

    File file = new File("song.mp3");

    FileInputStream fIn = new FileInputStream("song.mp3");
    FileOutputStream fOut = new FileOutputStream("song_0.mp3");
    int chunk_size = 1024 * 100;
    byte[] buff = new byte[chunk_size]; // 100KB file
    int i = 0;
    String file_name = file.getName();
    String file_name_base = file_name.substring(0, file_name.lastIndexOf("."));
    while (fIn.read() != -1) {

        fIn.read(buff);
        int total_read = 0;
        total_read += chunk_size;
        long read_next_chunk = total_read;
        String file_name_new = file_name_base + "_" + i + ".mp3";
        File file_new = new File(file_name_base);
        i++;
        fOut = new FileOutputStream(file_name_new);
        fOut.write(buff);

        fIn.skip(total_read);// skip the total read part

    } // end of while loop

    fIn.close();
    fOut.close();

}

The incremental variable declaration (int i = 0) was needed to create outside the while loop.
Don't null the variable buff as it will throw Null-pointer in next iteration.
File's base name needed to be extracted in order to create the file parts with names you want. E.g.  song_0.mp3, song_1.mp3,...

