Here you can find the source of CopyFile(String sourceFilePath, String destinationFilePath)
Parameter | Description |
---|---|
sourceFilePath | Source file path |
destinationFilePath | Destination file path |
Parameter | Description |
---|---|
Exception | an exception |
public static void CopyFile(String sourceFilePath, String destinationFilePath) throws Exception
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.io.*; public class Main { /** Copies a file from one location to another. */* w w w .j a va 2 s . co m*/ * @param sourceFilePath Source file path * @param destinationFilePath Destination file path * @throws Exception */ public static void CopyFile(String sourceFilePath, String destinationFilePath) throws Exception { File sourceFile = new File(sourceFilePath); if (sourceFile.exists()) { File destinationFile = new File(destinationFilePath); InputStream in = new FileInputStream(sourceFile); OutputStream out = new FileOutputStream(destinationFile); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len); in.close(); out.close(); } } }