EN
Java - copy file example
0 points
In this article, we would like to show you how to copy files in Java.
xxxxxxxxxx
1
import java.io.IOException;
2
import java.nio.file.Files;
3
import java.nio.file.Path;
4
import java.nio.file.Paths;
5
import java.nio.file.StandardCopyOption;
6
7
public class Example {
8
9
public static void main(String[] args) throws IOException {
10
Path sourcePath = Paths.get("C:\\path\\to\\file.txt");
11
Path destinationPath = Paths.get("C:\\path\\to\\file_copy.txt");
12
Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
13
}
14
}
Result:

