Here you can find the source of copyFile(String source, String targetDirectory, String filesep)
public static void copyFile(String source, String targetDirectory, String filesep) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void copyFile(String source, String targetDirectory, String filesep) throws IOException { byte[] buffer = new byte[4096]; int bytes_read; FileInputStream fis = null; FileOutputStream fos = null; File fileToCopy = null;/*from ww w. j a v a 2s . co m*/ File copiedFile = null; try { fileToCopy = new File(System.getProperty("user.dir") + filesep + source); copiedFile = new File(System.getProperty("user.dir") + filesep + targetDirectory + filesep + source); fis = new FileInputStream(fileToCopy); fos = new FileOutputStream(copiedFile); while ((bytes_read = fis.read(buffer)) != -1) { fos.write(buffer, 0, bytes_read); } //end while fos.flush(); fos.close(); } //end try catch (java.io.IOException ioe) { System.err.println("An error has occurred while copying file:\n" + ioe); ioe.printStackTrace(); return; } } }