import lombok.extern.slf4j.Slf4j;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
@Slf4j
public class TestByteBufferTransferTO {
public static void main(String[] args) {
try (FileChannel from = new FileInputStream("C:\\Users\\lets01\\Downloads\\CentOS-8.3.2011-x86_64-dvd1.iso").getChannel();
FileChannel to = new FileOutputStream("centos.iso").getChannel()
) {
long size = from.size();
for (long left = size; left > 0; ) {
log.info("position:{},left:{}", size - left, left);
left -= from.transferTo((size - left), left, to);
}
} catch (IOException e) {
log.debug("e:{}", e);
}
}
}