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 copy(String fromFile, String toFile) { InputStream in = null; OutputStream out = null; try { in = new FileInputStream(new File(fromFile)); out = new FileOutputStream(new File(toFile)); copy(in, out); } catch (Exception e) { return false; } finally { if (in != null) try { in.close(); } catch (Exception e) { } if (out != null) try { out.close(); } catch (Exception e) { } ; } return true; } public static long copy(InputStream from, OutputStream to) throws IOException { byte[] buf = new byte[4096]; long total = 0L; while (true) { int r = from.read(buf); if (r == -1) { return total; } to.write(buf, 0, r); total += (long) r; } } }