Here you can find the source of copyFile(File srcPath, File dstPath)
public static void copyFile(File srcPath, File dstPath) throws FileNotFoundException, IOException
//package com.java2s; //License from project: GNU General Public License import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyFile(File srcPath, File dstPath) throws FileNotFoundException, IOException { InputStream in = new FileInputStream(srcPath); OutputStream out = new FileOutputStream(dstPath); copy(in, out);//from ww w .java 2s . c o m in.close(); out.close(); } public static void copyFile(byte[] data, File dstPath) throws FileNotFoundException, IOException { InputStream in = new ByteArrayInputStream(data); OutputStream out = new FileOutputStream(dstPath); copy(in, out); in.close(); out.close(); } private static void copy(InputStream in, OutputStream out) throws IOException { // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } }