We would like to know how to copy File with java.nio.file.Files.
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; /*from w w w . ja v a 2 s . c o m*/ public class Main { public static void main(String[] args) throws Exception { Path newFile = FileSystems.getDefault().getPath("C:/home/docs/newFile.txt"); Path copiedFile = FileSystems.getDefault().getPath( "C:/home/docs/copiedFile.txt"); Files.createFile(newFile); System.out.println("File created successfully!"); Files.copy(newFile, copiedFile); System.out.println("File copied successfully!"); Files.copy(newFile, copiedFile, StandardCopyOption.REPLACE_EXISTING); } }