Here you can find the source of copyFile(File srcFile, File detFolder)
public static void copyFile(File srcFile, File detFolder)
//package com.java2s; /*//from www . j av a 2 s.c o m * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; public class Main { public static void copyFile(File srcFile, File detFolder) { BufferedInputStream bin = null; BufferedOutputStream bout = null; try { String fileName = srcFile.getName(); String targetFileName = detFolder.getAbsolutePath() + File.separatorChar + fileName; bin = new BufferedInputStream(new FileInputStream(srcFile)); bout = new BufferedOutputStream(new FileOutputStream(new File(targetFileName))); byte[] buffer = new byte[1024]; int count = 0; while ((count = bin.read(buffer, 0, 1024)) != -1) { bout.write(buffer, 0, count); } bout.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (bin != null) bin.close(); if (bout != null) bout.close(); } catch (Exception e) { } } } }