Java tutorial
//package com.java2s; 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 { private static int BUFFSIZE = 1024 * 8; public static void copyFile(File srcFile, File desFile) throws FileNotFoundException, IOException { try { File parent = desFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } } catch (Exception e) { } // InputStream input = new FileInputStream(srcFile); OutputStream output = new FileOutputStream(desFile); copyFileStream(input, output); } public static void copyFileStream(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[BUFFSIZE]; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } input.close(); output.close(); } }