import java.nio.file.*;
import java.io.IOException;
public class AdvancedFileCopy {
public static void main(String[] args) {
Path source = Paths.get("source.txt");
Path target = Paths.get("destination.txt");
try {
// REPLACE_EXISTING ensures it overwrites if the file is there
// COPY_ATTRIBUTES preserves file metadata like creation time
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES);
System.out.println("File copied successfully.");
} catch (IOException e) {
System.err.println("Failed to copy file: " + e.getMessage());
}
}
}
import java.nio.file.*;
import java.io.IOException;
public class AdvancedFileCopy {
public static void main(String[] args) {
Path source = Paths.get("source.txt");
Path target = Paths.get("destination.txt");
}