Here you can find the source of copyFile(String sourceFile, String destFile)
copyFile (source,dest)
copies the file from one location to another one
Parameter | Description |
---|---|
sourceFile | file to be copied |
destFile | copy location |
Parameter | Description |
---|---|
IOException | file not found, copy error |
public static void copyFile(String sourceFile, String destFile) 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.io.InputStream; import java.io.OutputStream; public class Main { /**//from w ww. j a v a 2s .c om * <code>copyFile (source,dest)</code> copies the file from one location to another one * @param sourceFile file to be copied * @param destFile copy location * @throws IOException file not found, copy error */ public static void copyFile(String sourceFile, String destFile) throws IOException { InputStream in = new FileInputStream(sourceFile); OutputStream out = new FileOutputStream(destFile); byte[] buffer = new byte[1024]; int length; //copy the file content in bytes while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } }