Languages
[Edit]
EN

Java - copy file example

0 points
Created by:
Yusef-Ewing
479

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
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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