FileChannel: transferFrom(ReadableByteChannel src, long position, long count)

abstract long transferFrom(ReadableByteChannel src, long position, long count)
Transfers bytes into channel's file from the given readable byte channel.
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class Main {

  public static void main(String[] args) {
    FileChannel in = null;
    FileChannel out = null;

    if (args.length < 2) {
      System.out.println("Usage: java Copy <from> <to>");
      System.exit(1);
    }

    try {
      in = new FileInputStream(args[0]).getChannel();
      out = new FileOutputStream(args[1]).getChannel();
      out.transferFrom(in, 0L, (int) in.size());

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

}
  
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)