Here you can find the source of copyFile(String oldPath, String newPath)
public static void copyFile(String oldPath, String newPath)
//License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import javax.servlet.ServletContext; public class Main{ public static void copyFile(String oldPath, String newPath) { try {/*from w ww . j av a 2 s .c o m*/ int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { InputStream inStream = new FileInputStream(oldPath); FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[10000]; while ((byteread = inStream.read(buffer)) != -1) { fs.write(buffer, 0, byteread); } inStream.close(); fs.close(); } } catch (Exception e) { e.printStackTrace(); } } }