Java tutorial
//package com.java2s; //License from project: Open Source License 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 void copyFiles(File source, File dest) throws IOException { copyFiles(getFileAsInputStream(source), dest); } private static void copyFiles(InputStream source, File dest) throws IOException { OutputStream output = null; int bytesRead = 0; byte[] buf = null; try { output = new FileOutputStream(dest); buf = new byte[1024]; while ((bytesRead = source.read(buf)) > 0) { output.write(buf, 0, bytesRead); } } finally { source.close(); output.close(); bytesRead = 0; output = null; source = null; buf = null; } } private static InputStream getFileAsInputStream(File file) throws FileNotFoundException { return new FileInputStream(file); } }