Here you can find the source of copyFile(File src, File dst)
private static void copyFile(File src, File dst) throws IOException
//package com.java2s; /*/*from w w w .j a va 2s.c om*/ * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { private static final int COPY_BUFFER_SIZE = 64 * 1024; private static void copyFile(File src, File dst) throws IOException { byte[] buffer = new byte[COPY_BUFFER_SIZE]; InputStream in = new FileInputStream(src); try { long srcLMD = 0L; srcLMD = src.lastModified(); if (srcLMD == 0) { throw new IOException("Failed to get the last modification " + "time of " + src.getAbsolutePath()); } OutputStream out = new FileOutputStream(dst); try { int ln; while ((ln = in.read(buffer)) != -1) { out.write(buffer, 0, ln); } } finally { out.close(); } if (srcLMD != 0L) { if (!dst.setLastModified(srcLMD)) { throw new IOException("Failed to set last-modification-date for: " + dst.getAbsolutePath()); } } } finally { in.close(); } } }