Java Files copy files and replace
import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; public class Main { public static void main(String[] args) { Path newFile = FileSystems.getDefault().getPath("Main.java"); Path copiedFile = FileSystems.getDefault().getPath("Main.txt"); try {//from ww w . j a va 2 s .c om Files.copy(newFile, copiedFile, StandardCopyOption.REPLACE_EXISTING); System.out.println("File copied successfully!"); } catch (IOException e) { System.out.println("IO Exception."); } } }