title: How to split a video file into multiple video files in Java
body: <p>I started learning about java coding and I want to split the video file, so here I obtained the code from <code>youtube</code>. The code split the file into parts of required mb I did some modification <strong>wanting it to split the file into required number of parts</strong>. This original code splits the file into <code>16 mb</code> here :</p>
  
  <pre><code>if(e==1024*1024*16) // split the file to 16 mb for each part
          {
              e =0L;
              fout.close();
              doPart();
          }
  </code></pre>
  
  <p>so if I put want the value in kb eg. 300kb for each part, the program just does not split the file for me.</p>
  
  <pre><code>    package fsplit;
  
      import java.io.File;
      import java.io.RandomAccessFile;
  
      public class SplitVid {
      public static void main(String args[])
      {
          try {
              new SplitVid();
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      } // end main
      File f=new File("thisfile.mp4");
      long fsize = f.length()/1024; // file size in bytes
      long parts = 9; // Divide the file into how many parts?
      long fsizeOfEachinkB = fsize/parts;
      int readInt;
      RandomAccessFile fin, fout;
      byte b[] = new byte[2048];
      long e = 0L;
      int j = 1;
      public SplitVid() throws Exception
      {
          fin=new RandomAccessFile(f, "r");
          doPart();
  
      }
  
      public void doPart() throws Exception
      {
          fout = new RandomAccessFile(f.getPath() + "Part"+j++, "rw");
  
          while((readInt = fin.read(b))!= -1)
          {
              fout.write(b, 0, readInt);
              e+= readInt;
  
  
              **if(e==1024*fsizeOfEachinkB)//divide each file into fsize/parts per file**
              {
                  e =0L;
                  fout.close();
                  doPart();
              }
          }
          System.out.println("The size of this file is " + f.length()/1024 + " kb");
          System.out.println("The file is divided into " + parts + " parts");
          System.out.println("Each part has " + fsizeOfEachinkB + " kb");
          fout.close();
          fin.close();
          f.delete(); // deletes the original file after the split is done
  
      }
  
  
  } //end class
  </code></pre>
  
  <p>Now if I increase 'parts' until <code>fsizeOfEachinkB</code> is less than <code>1 mb</code>, then the program just does not split the files at all. Anyone please help me looking into this ?</p>