Here you can find the source of copyFileUsingFileChannels(File source, File dest)
Parameter | Description |
---|---|
source | a parameter |
dest | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFileUsingFileChannels(File source, File dest) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /**// w ww. j av a2s .c o m * @param source * @param dest * @throws IOException */ public static void copyFileUsingFileChannels(File source, File dest) throws IOException { FileChannel inputChannel = null; FileChannel outputChannel = null; try { inputChannel = new FileInputStream(source).getChannel(); outputChannel = new FileOutputStream(dest).getChannel(); outputChannel.transferFrom(inputChannel, 0, inputChannel.size()); } catch (Exception e) { e.printStackTrace(); e.printStackTrace(System.out); } finally { if (inputChannel != null) inputChannel.close(); if (outputChannel != null) outputChannel.close(); } } }