Here you can find the source of copyFile(Path source, Path target, boolean okToOverwrite, boolean preserveAttributes)
Parameter | Description |
---|---|
source | the source directory |
target | the target directory |
okToOverwrite | The okToOverwrite parameter determines if an existing target can be overwritten |
preserveAttributes | The preserveAttributes parameter determines if file attributes should be copied/preserved. |
public static void copyFile(Path source, Path target, boolean okToOverwrite, boolean preserveAttributes) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; public class Main { /**/* www. j av a 2 s.c o m*/ * Copy source file to target location. * @param source the source directory * @param target the target directory * @param okToOverwrite The {@code okToOverwrite} parameter determines if an existing target can be overwritten * @param preserveAttributes The {@code preserveAttributes} parameter determines if file attributes should be copied/preserved. */ public static void copyFile(Path source, Path target, boolean okToOverwrite, boolean preserveAttributes) throws IOException { CopyOption[] options = (preserveAttributes) ? new CopyOption[] { StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING } : new CopyOption[] { StandardCopyOption.REPLACE_EXISTING }; if (Files.notExists(target) || okToOverwrite) { Files.copy(source, target, options); } } }