Here you can find the source of copyFileToDestDir(String srcFilePath, String destFileDir)
public static void copyFileToDestDir(String srcFilePath, String destFileDir) throws IOException
//package com.java2s; /* Copyright 2012, 2013 Unconventional Thinking * * This file is part of Hierarchy.// ww w . j a v a 2s.c o m * * Hierarchy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Hierarchy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with Hierarchy. * If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyFileToDestDir(String srcFilePath, String destFileDir) throws IOException { File srcFile = new File(srcFilePath); File destFile = new File(destFileDir + "/" + srcFile.getName()); copyFile(srcFile, destFile); } public static void copyFileToDestDir(File srcFile, String destFileDir) throws IOException { File destFile = new File(destFileDir + "/" + srcFile.getName()); copyFile(srcFile, destFile); } public static void copyFileToDestDir(File srcFile, File destDir) throws IOException { File destFile = new File(destDir, srcFile.getName()); copyFile(srcFile, destFile); } public static void copyFile(String srcFilePath, String destFilePath) throws IOException { File srcFile = new File(srcFilePath); File destFile = new File(destFilePath); copyFile(srcFile, destFile); } public static void copyFile(File srcFile, File destFile) throws IOException { if (srcFile == null) { throw new IOException("the path to the src file is null."); } if (!srcFile.exists()) { throw new IOException("For the move operation, the path to the src file does not exist: " + srcFile.getAbsolutePath()); } InputStream in = new FileInputStream(srcFile); //For Overwrite the file. OutputStream out = new FileOutputStream(destFile); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } }