FileChannel: transferFrom(ReadableByteChannel src, long position, long count) : FileChannel « java.nio.channels « Java by API






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

 

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

}

   
  








Related examples in the same category

1.FileChannel.MapMode.READ_ONLY
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: transferTo(long position, long count, WritableByteChannel target)
11.FileChannel: tryLock()
12.FileChannel: write(MappedByteBuffer buffer)
13.FileChannel: write(ByteBuffer buffer)