Here you can find the source of copyFile(String sourcePath, String destPath)
Parameter | Description |
---|---|
sourceFile | a parameter |
destFile | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(String sourcePath, String destPath) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /**/* ww w . j a va2s.com*/ * Copies one file to another. * From: http://stackoverflow.com/a/115086/352456 * @param sourceFile * @param destFile * @throws IOException */ public static void copyFile(String sourcePath, String destPath) throws IOException { File sourceFile = new File(sourcePath); File destFile = new File(destPath); 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(); } } } }