import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public class Copier {
public static void main(String[] args) throws IOException {
//Copy file /foo/x.txt to /bar directory
String source = "./foo/x.txt";
String target = "./bar/x.txt";
Copier.copyFile(source, target);
}
public static void copyFile(String source, String target) {
try {
Files.copy(new File(source).toPath(), new File(target).toPath(),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public class Copier {
public static void main(String[] args) throws IOException {
//Copy file /foo/x.txt to /bar directory
String source = "./foo/x.txt";
String target = "./bar/x.txt";
Copier.copyFile(source, target);
}
public static void copyFile(String source, String target) {
try {
Files.copy(new File(source).toPath(), new File(target).toPath(),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}