FileChannel: transferTo(long position, long count, WritableByteChannel target)

abstract long transferTo(long position, long count, WritableByteChannel target)
Transfers bytes from this channel's file to the given writable byte channel.

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

public class MainClass {

  public static void main(String[] args) throws Exception{
    String fromFileName = args[0];
    String toFileName = args[1];
    FileChannel in = new FileInputStream(fromFileName).getChannel();
    FileChannel out = new FileOutputStream(toFileName).getChannel();
    in.transferTo(0, (int) in.size(), out);
    in.close();
    out.close();
  }
}
Home 
  Java Book 
    File Stream  

FileChannel:
  1. FileChannel
  2. FileChannel.MapMode.READ_WRITE
  3. FileChannel: close()
  4. FileChannel: lock(long position, long size, boolean shared)
  5. FileChannel: map(MapMode mode, long position, long size)
  6. FileChannel: position()
  7. FileChannel: position(long newPosition)
  8. FileChannel: read(ByteBuffer dst)
  9. FileChannel: size()
  10. FileChannel: transferFrom(ReadableByteChannel src, long position, long count)
  11. FileChannel: transferTo(long position, long count, WritableByteChannel target)
  12. FileChannel: tryLock()
  13. FileChannel: write(MappedByteBuffer buffer)