Split file : FileOutputStream « File Input Output « Java






Split file

   

import java.io.FileInputStream;
import java.io.FileOutputStream;

class FileSplitter {

  public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);
    int size = 1024;
    byte buffer[] = new byte[size];

    int count = 0;
    while (true) {
      int i = fis.read(buffer, 0, size);
      if (i == -1)
        break;

      String filename = args[1] + count;
      FileOutputStream fos = new FileOutputStream(filename);
      fos.write(buffer, 0, i);
      fos.flush();
      fos.close();

      ++count;
    }
  }
}

   
    
    
  








Related examples in the same category

1.File IO
2.Copy Bytes between FileInputStream and FileOutputStream
3.Copy byte between FileInputStream and FileOutputStream
4.Write byte array to a file using FileOutputStream
5.Create DataOutputStream from FileOutputStream
6.Write double to a file using DataOutputStream
7.Append output to file using FileOutputStream
8.Create FileOutputStream object from File object
9.Create FileOutputStream object from String file path
10.Write file using FileOutputStream
11.Use FileOutputStream to write the bytes to a file.
12.Write UTF String, integer and double with DataOutputStream
13.Write data with FileOutputStream
14.Rollover FileOutputStream