EN
Java - copy file example
0
points
In this article, we would like to show you how to copy files in Java.
Practical example
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
public class Example {
public static void main(String[] args) throws IOException {
Path sourcePath = Paths.get("C:\\path\\to\\file.txt");
Path destinationPath = Paths.get("C:\\path\\to\\file_copy.txt");
Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
}
}
Result: