import java.io.*;
import java.nio.channels.*;
import java.nio.file.*;

public class Transfer2GPlus {
    public static void main(String[] args) throws Exception {
        final String name = "src.dat";
        RandomAccessFile raf = new RandomAccessFile(name, "rw");
        final long length = (long)Integer.MAX_VALUE + 1024L;
        raf.setLength(length);

        Path path = Path.of("dst.dat");
        try (FileChannel src = FileChannel.open(Path.of(name))) {
            Files.createFile(path);
            try (FileChannel dst = FileChannel.open(path,
                 StandardOpenOption.WRITE)) {
                src.transferTo(0, length, dst);
                if (dst.size() < length)
                    throw new RuntimeException("Not enough bytes transferred " +
                        dst.size() + " < " + length);
            } finally {
                Files.delete(path);
            }
        } finally {
            Files.delete(Path.of(name));
        }
    }
}
