Here you can find the source of copyFileToDir(File sourceFile, File destDir)
public static void copyFileToDir(File sourceFile, File destDir) throws IOException
//package com.java2s; //Copyright 2010 ThoughtWorks, Inc. Licensed under the Apache License, Version 2.0. import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.FileOutputStream; public class Main { public static void copyFileToDir(File sourceFile, File destDir) throws IOException { FileInputStream in = new FileInputStream(sourceFile); FileOutputStream out = new FileOutputStream( destDir.getAbsolutePath() + File.separator + sourceFile.getName()); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = in.read(buffer)) > -1) { out.write(buffer, 0, bytesRead); }// ww w . j av a 2 s . c o m out.flush(); out.close(); } }