Here you can find the source of copyFile(Path source, Path destination, CopyOption... options)
public static void copyFile(Path source, Path destination, CopyOption... options) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.CopyOption; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; public class Main { public static void copyFile(Path source, Path destination, CopyOption... options) throws IOException { if (source == null) { throw new IllegalArgumentException("Source cannot be null."); }/*w w w .j av a2s. c om*/ if (destination == null) { throw new IllegalArgumentException("Destination cannot be null."); } if (!Files.exists(source)) { throw new FileNotFoundException(source.toString()); } if (Files.exists(destination) && !arrayContains(options, StandardCopyOption.REPLACE_EXISTING)) { throw new FileAlreadyExistsException(destination.toString()); } } private static boolean arrayContains(CopyOption[] options, StandardCopyOption replaceExisting) { if (options == null || options.length == 0) { return false; } for (int i = 0; i < options.length; i++) { if (options.equals(replaceExisting)) { return true; } } return false; } }