Use BufferedInputStream and BufferedOutputStream to copy byte array : Buffer Stream « File Input Output « Java






Use BufferedInputStream and BufferedOutputStream to copy byte array


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Main {
  public static void main(String[] args) throws Exception {
    String fromFileName = "from.txt";
    String toFileName = "to.txt";
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(fromFileName));
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(toFileName));
    byte[] buff = new byte[32 * 1024];
    int len;
    while ((len = in.read(buff)) > 0)
      out.write(buff, 0, len);
    in.close();
    out.close();
  }
}

 








Related examples in the same category

1.Use buffered input.
2.Writing to a Binary File
3.Reading from a Binary File with BufferedInputStream