Here you can find the source of copyFile(String pathOld, String pathNew)
public static File copyFile(String pathOld, String pathNew)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static File copyFile(String pathOld, String pathNew) { File fileOld = new File(pathOld); File fileNew = new File(pathNew); if (fileOld.exists()) { try { FileInputStream fis = new FileInputStream(fileOld); FileOutputStream fos = new FileOutputStream(fileNew); int read = 0; while ((read = fis.read()) != -1) { fos.write(read);// w w w. j a va2s . c o m fos.flush(); } fos.close(); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return fileNew; } }