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