Here you can find the source of copyFile(Path source, Path target, boolean prompt, boolean preserve)
private static void copyFile(Path source, Path target, boolean prompt, boolean preserve)
//package com.java2s; /*//from w w w .j a v a 2 s .c o m * Copyright (C) 2011-2014 by Ahmed Osama el-Sawalhy * * The Modified MIT Licence (GPL v3 compatible) * License terms are in a separate file (LICENCE.md) * * Project/File: Overcast/com.yagasoft.overcast.base.container/FolderHelper.java * * Modified: Apr 15, 2014 (8:06:38 AM) * Using: Eclipse J-EE / JDK 7 / Windows 8.1 x64 */ import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import java.io.IOException; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; public class Main { /** * Copy source file to target location. If {@code prompt} is true then prompt user to overwrite target if it exists. The * {@code preserve} parameter determines if file attributes should be copied/preserved. */ private static void copyFile(Path source, Path target, boolean prompt, boolean preserve) { CopyOption[] options = (preserve) ? new CopyOption[] { COPY_ATTRIBUTES, REPLACE_EXISTING } : new CopyOption[] { REPLACE_EXISTING }; if (!prompt || Files.notExists(target)) // || okayToOverwrite(target)) { try { Files.copy(source, target, options); } catch (IOException x) { System.err.format("Unable to copy: %s: %s%n", source, x); } } } }