Here you can find the source of copy(File source, File target)
Parameter | Description |
---|---|
source | the file to be read |
target | the file to be written |
public static void copy(File source, File target) throws IOException
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; public class Main { /**//from w ww.j av a2 s. c o m * Copy one file to another * * @param source the file to be read * @param target the file to be written * * @exception IOException raised if operation fails */ public static void copy(File source, File target) throws IOException { FileChannel input = null; FileChannel output = null; try { input = new FileInputStream(source).getChannel(); output = new FileOutputStream(target).getChannel(); MappedByteBuffer buffer = input.map(FileChannel.MapMode.READ_ONLY, 0, input.size()); output.write(buffer); } finally { if (input != null) { input.close(); } if (output != null) { output.close(); } } } }