Here you can find the source of copyFile(File sourceFile, File destFile)
Parameter | Description |
---|---|
sourceFile | The source file. |
destFile | The destination file. |
Parameter | Description |
---|---|
IOException | If an IOException is thrown. |
public static void copyFile(File sourceFile, File destFile) 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; public class Main { /**//from w w w . j av a2 s . c o m * Copies a file. * * @param sourceFile The source file. * @param destFile The destination file. * @throws IOException If an IOException is thrown. */ public static void copyFile(File sourceFile, File destFile) throws IOException { FileOutputStream fos; try (FileInputStream fis = new FileInputStream(sourceFile)) { fos = new FileOutputStream(destFile); fis.getChannel().transferTo(0, sourceFile.length(), fos.getChannel()); } fos.close(); } }