FileOutputStream: getChannel() : FileOutputStream « java.io « Java by API






FileOutputStream: getChannel()

 

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
  private static final int BSIZE = 1024;

  public static void main(String[] args) throws Exception {
    FileChannel in = new FileInputStream("source.txt").getChannel(), out = new FileOutputStream(
        "target.txt").getChannel();
    ByteBuffer buffer = ByteBuffer.allocate(BSIZE);
    while (in.read(buffer) != -1) {
      buffer.flip();
      out.write(buffer);
      buffer.clear();
    }
  }
}

   
  








Related examples in the same category

1.new FileOutputStream(File file)
2.new FileOutputStream(String name)
3.FileOutputStream: getFD()
4.FileOutputStream: write(int b)