import java.nio.file.*;
import java.io.IOException;
public class AdvancedFileIO {
public static void copyFile(String sourcePath, String destPath) {
Path source = Paths.get(sourcePath);
Path target = Paths.get(destPath);
try {
// StandardCopyOption.REPLACE_EXISTING ensures it overwrites if file exists
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
System.out.println("File copied successfully!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.nio.file.*;
import java.io.IOException;
public class AdvancedFileIO {
public static void copyFile(String sourcePath, String destPath) {
Path source = Paths.get(sourcePath);
Path target = Paths.get(destPath);
try {
// StandardCopyOption.REPLACE_EXISTING ensures it overwrites if file exists
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
System.out.println("File copied successfully!");
} catch (IOException e) {
e.printStackTrace();
}
}
}