Here you can find the source of copyFile(Path source, Path target)
public static void copyFile(Path source, Path target) throws IOException
//package com.java2s; /*/* w w w .j a v a 2 s. com*/ * Copyright (c) 2015-2017, Excelsior LLC. * * This file is part of Excelsior JET API. * * Excelsior JET API 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. * * Excelsior JET API 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 Excelsior JET API. * If not, see <http://www.gnu.org/licenses/>. * */ import java.io.*; import java.nio.file.*; public class Main { public static void copyFile(Path source, Path target) throws IOException { if (!target.toFile().exists()) { Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES); } else if (source.toFile().lastModified() != target.toFile().lastModified()) { //copy only files that were changed Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); } } public static void copy(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024 * 1024]; int len; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } } }