Class CopyFileVisitor

  • All Implemented Interfaces:
    java.nio.file.FileVisitor<java.nio.file.Path>

    public final class CopyFileVisitor
    extends java.nio.file.SimpleFileVisitor<java.nio.file.Path>
    Represents a FileVisitor which will create a copy of a directory and its contents.

    Example usage:
    Files.walkFileTree(dir, new CopyFileVisitor(target);

    • Constructor Summary

      Constructors 
      Constructor Description
      CopyFileVisitor​(java.nio.file.Path target, java.nio.file.CopyOption... options)
      Constructs a new CopyFileVisitor which will copy the visited file paths to the specified target directory.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.nio.file.FileVisitResult preVisitDirectory​(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attrs)  
      java.nio.file.FileVisitResult visitFile​(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs)  
      • Methods inherited from class java.nio.file.SimpleFileVisitor

        postVisitDirectory, visitFileFailed
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CopyFileVisitor

        public CopyFileVisitor​(java.nio.file.Path target,
                               java.nio.file.CopyOption... options)
        Constructs a new CopyFileVisitor which will copy the visited file paths to the specified target directory.

        Note: The target directory must not exist since the visitor will also copy the root directory to the specified location.

        Parameters:
        target - The path to copy the visited files to
        options - Optional options for the copy operations
    • Method Detail

      • preVisitDirectory

        public java.nio.file.FileVisitResult preVisitDirectory​(java.nio.file.Path dir,
                                                               java.nio.file.attribute.BasicFileAttributes attrs)
                                                        throws java.io.IOException
        Specified by:
        preVisitDirectory in interface java.nio.file.FileVisitor<java.nio.file.Path>
        Overrides:
        preVisitDirectory in class java.nio.file.SimpleFileVisitor<java.nio.file.Path>
        Throws:
        java.io.IOException
      • visitFile

        public java.nio.file.FileVisitResult visitFile​(java.nio.file.Path file,
                                                       java.nio.file.attribute.BasicFileAttributes attrs)
                                                throws java.io.IOException
        Specified by:
        visitFile in interface java.nio.file.FileVisitor<java.nio.file.Path>
        Overrides:
        visitFile in class java.nio.file.SimpleFileVisitor<java.nio.file.Path>
        Throws:
        java.io.IOException