Here you can find the source of copyFile(Path from, Path to)
public static void copyFile(Path from, Path to)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; public class Main { /** Copy file */ public static void copyFile(Path from, Path to) { try {/*from w w w.j a v a2 s . co m*/ to.getParent().toFile().mkdirs(); Files.copy(from, to); } catch (FileAlreadyExistsException e) { } catch (IOException e) { fatal("An error occured while writing " + to.toString(), e); return; } } /** Print fatal error and exit. */ public static <T> T fatal(String message, Exception e) { System.out.println(message); if (e != null && System.getProperty("stacktrace") != null) e.printStackTrace(); System.exit(0); return (T) null; } }