Here you can find the source of copyFile(String sourceFile, String targetFile)
public static boolean copyFile(String sourceFile, String targetFile)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; public class Main { public static boolean copyFile(String sourceFile, String targetFile) { File file1 = new File(sourceFile); File file2 = new File(targetFile); FileInputStream fis = null; FileOutputStream fos = null; boolean isOK = true; try {//from www. j a v a 2 s . c o m if (file1.exists()) { if (!file2.exists()) { file2.createNewFile(); } fis = new FileInputStream(file1); byte[] buffer = new byte[(int) file1.length()]; fis.read(buffer); fos = new FileOutputStream(file2); fos.write(buffer); } else { isOK = false; } } catch (Exception e) { System.out.println(e); isOK = false; } finally { try { fis.close(); } catch (Exception ex) { } try { fos.close(); } catch (Exception ex) { } } return isOK; } }