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
Java Book
File Stream
FileChannel:
- FileChannel
- FileChannel.MapMode.READ_WRITE
- FileChannel: close()
- FileChannel: lock(long position, long size, boolean shared)
- FileChannel: map(MapMode mode, long position, long size)
- FileChannel: position()
- FileChannel: position(long newPosition)
- FileChannel: read(ByteBuffer dst)
- FileChannel: size()
- FileChannel: transferFrom(ReadableByteChannel src, long position, long count)
- FileChannel: transferTo(long position, long count, WritableByteChannel target)
- FileChannel: tryLock()
- FileChannel: write(MappedByteBuffer buffer)