Here you can find the source of copyFile(File sourceFile, File destFile)
Parameter | Description |
---|---|
sourceFile | a parameter |
destFile | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File sourceFile, File destFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.channels.FileChannel; public class Main { /**// ww w .ja v a2s. co m * (Copied from stackoverflow). Utility method for copying an arbitrary file. * @param sourceFile * @param destFile * @throws IOException */ public static void copyFile(File sourceFile, File destFile) throws IOException { if (!destFile.exists()) { destFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if (source != null) { source.close(); } if (destination != null) { destination.close(); } } } }