code: public static void copyRecursively(Path source, Path destination) throws IOException {
          if (Files.isDirectory(source))
          {
              Files.createDirectories(destination);
              final Set<Path> sources = listFiles(source);
  
              for (Path srcFile : sources)
              {
                  Path destFile = destination.resolve(srcFile.getFileName());
                  copyRecursively(srcFile, destFile);
              }
          }
          else
          {
              Files.copy(source, destination, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
          }
      }
docs: Copy a directory recursively, preserving attributes, in particular permissions.