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 { /**/* ww w. j a v a2 s. com*/ * 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 { FileChannel in = null; FileChannel out = null; try { in = new FileInputStream(origPath).getChannel(); out = new FileOutputStream(destPath).getChannel(); in.transferTo(0, in.size(), out); } finally { if (in != null) in.close(); if (out != null) out.close(); } } }