Here you can find the source of copyFile(String oldPath, String newPath)
public static void copyFile(String oldPath, String newPath) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void copyFile(String oldPath, String newPath) throws IOException { int byteread = 0; File oldfile = new File(oldPath); InputStream inStream = null; FileOutputStream outStream = null; if (oldfile.exists()) { try { inStream = new FileInputStream(oldPath); outStream = new FileOutputStream(newPath); byte[] buffer = new byte[1024]; while ((byteread = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, byteread); }//from ww w.jav a 2 s .c o m } catch (IOException ioe) { throw ioe; } finally { try { if (inStream != null) inStream.close(); if (outStream != null) outStream.close(); } catch (IOException e) { throw e; } } } } }