Languages
[Edit]
EN

Java - copy file example

0 points
Created by:
Yusef-Ewing
269

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: 

Java - copy file example
Before execution
Java - copy file example
After execution

Java - file operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join