Here you can find the source of copyFile(String origPath, String destPath)
Parameter | Description |
---|---|
origPath | Original path |
destPath | Destination path |
Parameter | Description |
---|---|
IOException | If the operation fails during the data copy phase or,FileNotFoundException if either file exists but is a directoryrather than a regular file, does not exist but cannot be read/created,or cannot be opened for any other reason. |
public static void copyFile(String origPath, String destPath) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /**/*from www . ja va 2 s . c om*/ * Convenience function to copy a file. * <p> * If the destination file exists it is overwritten. * * @param origPath Original path * @param destPath Destination path * @throws IOException If the operation fails during the data copy phase or, * {@link FileNotFoundException} if either file exists but is a directory * rather than a regular file, does not exist but cannot be read/created, * or cannot be opened for any other reason. */ public static void copyFile(String origPath, String destPath) throws IOException { FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(origPath); fos = new FileOutputStream(destPath); final FileChannel in = fis.getChannel(); final FileChannel out = fos.getChannel(); in.transferTo(0, in.size(), out); } finally { if (fis != null) fis.close(); if (fos != null) fos.close(); } } }