Java Path Copy nio copyFile(Path source, Path target, boolean prompt, boolean preserve)

Here you can find the source of copyFile(Path source, Path target, boolean prompt, boolean preserve)

Description

Copy source file to target location.

License

Open Source License

Declaration

static void copyFile(Path source, Path target, boolean prompt, boolean preserve) 

Method Source Code


//package com.java2s;
import java.nio.file.*;

import java.io.IOException;

public class Main {
    /**// w  ww.ja v a 2  s.c om
     * 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.
     */
    static void copyFile(Path source, Path target, boolean prompt, boolean preserve) {
        if (!prompt || Files.notExists(target)) {
            try {
                Files.copy(source, target);
            } catch (IOException x) {
                System.err.format("Unable to copy: %s: %s%n", source, x);
            }
        }
    }
}

Related

  1. copyFile(Path source, Path target)
  2. copyFile(Path source, Path target, boolean foreign, CopyOption... options)
  3. copyFile(Path source, Path target, boolean okToOverwrite, boolean preserveAttributes)
  4. copyFile(Path source, Path target, boolean prompt, boolean preserve)
  5. copyFile(Path source, Path target, boolean prompt, boolean preserve)
  6. copyFile(Path srcFile, Path srcDir, Path dstDir)
  7. copyFile(String srcPath, String destPath)
  8. copyFile(String urlPath, String outFile)
  9. copyFileFromResourcesToServer(String resourceFile, Path targetDirectory, boolean override)