Here you can find the source of copyDirectory(File source, File dest, CopyOption... options)
https://stackoverflow.com/questions/11651900/how-to-recursively-copy-entire-directory-including-parent-folder-in-java
Parameter | Description |
---|---|
source | - directory to copy from |
dest | - directory to copy to |
options | - copy mode |
Parameter | Description |
---|---|
IOException | - thrown by underlying nio calls |
private static void copyDirectory(File source, File dest, CopyOption... options) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.nio.file.*; public class Main { /**// ww w . ja v a2 s.c o m * https://stackoverflow.com/questions/11651900/how-to-recursively-copy-entire-directory-including-parent-folder-in-java * * @param source - directory to copy from * @param dest - directory to copy to * @param options - copy mode * @throws IOException - thrown by underlying nio calls */ private static void copyDirectory(File source, File dest, CopyOption... options) throws IOException { if (!dest.exists()) dest.mkdirs(); File[] contents = source.listFiles(); if (contents != null) { for (File f : contents) { File newFile = new File(dest.getAbsolutePath() + File.separator + f.getName()); if (f.isDirectory()) copyDirectory(f, newFile, options); else copyFile(f, newFile, options); } } } private static void copyFile(File source, File dest, CopyOption... options) throws IOException { Files.copy(source.toPath(), dest.toPath(), options); } }