Here you can find the source of copyFile(String from, String to)
public static void copyFile(String from, String to) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void copyFile(String from, String to) throws IOException { File inCannon = new File(from); File outCannon = new File(to); // [#20196] Installer overwrites the installed credentials if already installed credentials are selected // Applies to Windows only if (inCannon.equals(outCannon)) { return; }//from w ww . j av a 2 s. co m // ensure the output file location exists outCannon.getParentFile().mkdirs(); BufferedInputStream fis = new BufferedInputStream(new FileInputStream(inCannon)); BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(outCannon)); // a temporary buffer to read into byte[] tmpBuffer = new byte[8192]; int len = 0; while ((len = fis.read(tmpBuffer)) != -1) { // add the temp data to the output fos.write(tmpBuffer, 0, len); } // close the input stream fis.close(); // close the output stream fos.flush(); fos.close(); } }