-2

I want to copy files from directory to another, so I searched and I got this post: Copying files from one directory to another in Java

I follow the first answer, but I couldn't find the jar of FileUtils and the URL in the comments is broken.

Could you please help me to find the target jar?

Thank you in advance.

Community
  • 1
  • 1
Programer14
  • 165
  • 13

2 Answers2

2

You can either use the libary as mentioned but since Java7 there is a nice and quick way to do it with pure Java:

public static void copyDirectory(String input, String output) throws IOException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(input))) {
        for (Path entry: stream) {
            if (Files.isRegularFile(entry)) {
                Files.copy(entry, Paths.get(output).resolve(entry.getFileName()));
            }
        }
    }
}
user432
  • 3,506
  • 17
  • 24
1

You're looking for commons-io, FileUtils is a class from apache's commons-io.jar

http://commons.apache.org/proper/commons-io/

galmeida
  • 26
  • 2