Here you can find the source of copyFile(File sourceFile, String newFileName)
public static void copyFile(File sourceFile, String newFileName) throws java.io.FileNotFoundException, java.io.IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; public class Main { public static void copyFile(File sourceFile, String newFileName) throws java.io.FileNotFoundException, java.io.IOException { File newFile = new File(newFileName); copyFile(sourceFile, newFile);/*from ww w. ja v a2 s. c o m*/ } public static void copyFile(File sourceFile, File newFile) throws java.io.FileNotFoundException, java.io.IOException { java.io.FileInputStream input = new java.io.FileInputStream(sourceFile); if (!newFile.exists()) { newFile.createNewFile(); } java.io.FileOutputStream output = new FileOutputStream(newFile); byte buffer[] = new byte[1024]; int noRead = 0; noRead = input.read(buffer, 0, 1024); //Write out the stream to the file while (noRead != -1) { output.write(buffer, 0, noRead); noRead = input.read(buffer, 0, 1024); } output.flush(); output.close(); input.close(); } public static boolean exists(String path, String fileNameWithoutFullPath) { String filePath = getFileNameWithPath(path, fileNameWithoutFullPath); return exists(filePath); } public static boolean exists(String fileNameWithFullPath) { File file = new File(fileNameWithFullPath); return file.exists(); } public static String getFileNameWithPath(String path, String fileNameWithoutFullPath) { return path + File.separator + fileNameWithoutFullPath; } }