Here you can find the source of copyFileByMapped(String sourcePath, String targetPath)
public static final void copyFileByMapped(String sourcePath, String targetPath) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; public class Main { public static final void copyFileByMapped(String sourcePath, String targetPath) throws IOException { RandomAccessFile readFile = new RandomAccessFile(sourcePath, "r"); RandomAccessFile writeFile = new RandomAccessFile(targetPath, "rw"); long fileLength = readFile.length(); MappedByteBuffer in = readFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, fileLength); MappedByteBuffer out = writeFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, fileLength); for (int i = 0; i < fileLength; i++) { out.put(in.get());/*from www . ja va 2s. c om*/ } readFile.close(); writeFile.close(); in.clear(); out.clear(); } }