Java tutorial
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static boolean copyFile(File srcFile, File destFile) { boolean result = false; try { InputStream in = new FileInputStream(srcFile); try { result = copyToFile(in, destFile); } finally { in.close(); } } catch (IOException e) { result = false; } return result; } /** * Copy data from a source stream to destFile. Return true if succeed, * return false if failed. */ private static boolean copyToFile(InputStream inputStream, File destFile) { try { OutputStream out = new FileOutputStream(destFile); try { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) >= 0) { out.write(buffer, 0, bytesRead); } } finally { out.close(); } return true; } catch (IOException e) { return false; } } }