Class PathUtils


  • public final class PathUtils
    extends java.lang.Object
    NIO Path utilities.
    Since:
    2.7
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Counters.PathCounters cleanDirectory​(java.nio.file.Path directory)
      Cleans a directory including sub-directories without deleting directories.
      static Counters.PathCounters cleanDirectory​(java.nio.file.Path directory, DeleteOption... deleteOptions)
      Cleans a directory including sub-directories without deleting directories.
      static Counters.PathCounters copyDirectory​(java.nio.file.Path sourceDirectory, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)
      Copies a directory to another directory.
      static java.nio.file.Path copyFile​(java.net.URL sourceFile, java.nio.file.Path targetFile, java.nio.file.CopyOption... copyOptions)
      Copies a URL to a directory.
      static java.nio.file.Path copyFileToDirectory​(java.net.URL sourceFile, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)
      Copies a URL to a directory.
      static java.nio.file.Path copyFileToDirectory​(java.nio.file.Path sourceFile, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)
      Copies a file to a directory.
      static Counters.PathCounters countDirectory​(java.nio.file.Path directory)
      Counts aspects of a directory including sub-directories.
      static java.nio.file.Path createParentDirectories​(java.nio.file.Path path, java.nio.file.attribute.FileAttribute<?>... attrs)
      Creates the parent directories for the given path.
      static java.nio.file.Path current()
      Gets the current directory.
      static Counters.PathCounters delete​(java.nio.file.Path path)
      Deletes a file or directory.
      static Counters.PathCounters delete​(java.nio.file.Path path, java.nio.file.LinkOption[] linkOptions, DeleteOption... deleteOptions)
      Deletes a file or directory.
      static Counters.PathCounters delete​(java.nio.file.Path path, DeleteOption... deleteOptions)
      Deletes a file or directory.
      static Counters.PathCounters deleteDirectory​(java.nio.file.Path directory)
      Deletes a directory including sub-directories.
      static Counters.PathCounters deleteDirectory​(java.nio.file.Path directory, java.nio.file.LinkOption[] linkOptions, DeleteOption... deleteOptions)
      Deletes a directory including sub-directories.
      static Counters.PathCounters deleteDirectory​(java.nio.file.Path directory, DeleteOption... deleteOptions)
      Deletes a directory including sub-directories.
      static Counters.PathCounters deleteFile​(java.nio.file.Path file)
      Deletes the given file.
      static Counters.PathCounters deleteFile​(java.nio.file.Path file, java.nio.file.LinkOption[] linkOptions, DeleteOption... deleteOptions)
      Deletes the given file.
      static Counters.PathCounters deleteFile​(java.nio.file.Path file, DeleteOption... deleteOptions)
      Deletes the given file.
      static boolean directoryAndFileContentEquals​(java.nio.file.Path path1, java.nio.file.Path path2)
      Compares the file sets of two Paths to determine if they are equal or not while considering file contents.
      static boolean directoryAndFileContentEquals​(java.nio.file.Path path1, java.nio.file.Path path2, java.nio.file.LinkOption[] linkOptions, java.nio.file.OpenOption[] openOptions, java.nio.file.FileVisitOption[] fileVisitOption)
      Compares the file sets of two Paths to determine if they are equal or not while considering file contents.
      static boolean directoryContentEquals​(java.nio.file.Path path1, java.nio.file.Path path2)
      Compares the file sets of two Paths to determine if they are equal or not without considering file contents.
      static boolean directoryContentEquals​(java.nio.file.Path path1, java.nio.file.Path path2, int maxDepth, java.nio.file.LinkOption[] linkOptions, java.nio.file.FileVisitOption[] fileVisitOptions)
      Compares the file sets of two Paths to determine if they are equal or not without considering file contents.
      static boolean fileContentEquals​(java.nio.file.Path path1, java.nio.file.Path path2)
      Compares the file contents of two Paths to determine if they are equal or not.
      static boolean fileContentEquals​(java.nio.file.Path path1, java.nio.file.Path path2, java.nio.file.LinkOption[] linkOptions, java.nio.file.OpenOption[] openOptions)
      Compares the file contents of two Paths to determine if they are equal or not.
      static java.nio.file.Path[] filter​(PathFilter filter, java.nio.file.Path... paths)
      Applies an IOFileFilter to the provided File objects.
      static java.util.List<java.nio.file.attribute.AclEntry> getAclEntryList​(java.nio.file.Path sourcePath)
      Reads the access control list from a file attribute view.
      static boolean isDirectory​(java.nio.file.Path path, java.nio.file.LinkOption... options)
      Tests whether the specified Path is a directory or not.
      static boolean isEmpty​(java.nio.file.Path path)
      Tests whether the given file or directory is empty.
      static boolean isEmptyDirectory​(java.nio.file.Path directory)
      Tests whether the directory is empty.
      static boolean isEmptyFile​(java.nio.file.Path file)
      Tests whether the given file is empty.
      static boolean isNewer​(java.nio.file.Path file, long timeMillis, java.nio.file.LinkOption... options)
      Tests if the specified Path is newer than the specified time reference.
      static boolean isRegularFile​(java.nio.file.Path path, java.nio.file.LinkOption... options)
      Tests whether the specified Path is a regular file or not.
      static java.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream​(java.nio.file.Path dir, PathFilter pathFilter)
      Creates a new DirectoryStream for Paths rooted at the given directory.
      static java.nio.file.attribute.BasicFileAttributes readBasicFileAttributes​(java.nio.file.Path path)
      Shorthand for Files.readAttributes(path, BasicFileAttributes.class)
      static java.nio.file.attribute.BasicFileAttributes readBasicFileAttributesUnchecked​(java.nio.file.Path path)
      Shorthand for Files.readAttributes(path, BasicFileAttributes.class) while wrapping IOException as UncheckedIOException.
      static java.nio.file.Path setReadOnly​(java.nio.file.Path path, boolean readOnly, java.nio.file.LinkOption... linkOptions)
      Sets the given Path to the readOnly value.
      static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
      T
      visitFileTree​(T visitor, java.lang.String first, java.lang.String... more)
      Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
      static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
      T
      visitFileTree​(T visitor, java.net.URI uri)
      Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
      static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
      T
      visitFileTree​(T visitor, java.nio.file.Path directory)
      Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
      static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
      T
      visitFileTree​(T visitor, java.nio.file.Path start, java.util.Set<java.nio.file.FileVisitOption> options, int maxDepth)
      Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor.
      static java.util.stream.Stream<java.nio.file.Path> walk​(java.nio.file.Path start, PathFilter pathFilter, int maxDepth, boolean readAttributes, java.nio.file.FileVisitOption... options)
      Returns a stream of filtered paths.
      • Methods inherited from class java.lang.Object

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

      • EMPTY_COPY_OPTIONS

        public static final java.nio.file.CopyOption[] EMPTY_COPY_OPTIONS
        Empty CopyOption array.
        Since:
        2.8.0
      • EMPTY_DELETE_OPTION_ARRAY

        public static final DeleteOption[] EMPTY_DELETE_OPTION_ARRAY
        Empty LinkOption array.
        Since:
        2.8.0
      • EMPTY_FILE_VISIT_OPTION_ARRAY

        public static final java.nio.file.FileVisitOption[] EMPTY_FILE_VISIT_OPTION_ARRAY
        Empty FileVisitOption array.
      • EMPTY_LINK_OPTION_ARRAY

        public static final java.nio.file.LinkOption[] EMPTY_LINK_OPTION_ARRAY
        Empty LinkOption array.
      • NOFOLLOW_LINK_OPTION_ARRAY

        public static final java.nio.file.LinkOption[] NOFOLLOW_LINK_OPTION_ARRAY
        LinkOption array for LinkOption.NOFOLLOW_LINKS.
        Since:
        2.9.0
      • EMPTY_OPEN_OPTION_ARRAY

        public static final java.nio.file.OpenOption[] EMPTY_OPEN_OPTION_ARRAY
        Empty OpenOption array.
      • EMPTY_PATH_ARRAY

        public static final java.nio.file.Path[] EMPTY_PATH_ARRAY
        Empty Path array.
        Since:
        2.9.0
    • Method Detail

      • cleanDirectory

        public static Counters.PathCounters cleanDirectory​(java.nio.file.Path directory)
                                                    throws java.io.IOException
        Cleans a directory including sub-directories without deleting directories.
        Parameters:
        directory - directory to clean.
        Returns:
        The visitation path counters.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method.
      • cleanDirectory

        public static Counters.PathCounters cleanDirectory​(java.nio.file.Path directory,
                                                           DeleteOption... deleteOptions)
                                                    throws java.io.IOException
        Cleans a directory including sub-directories without deleting directories.
        Parameters:
        directory - directory to clean.
        deleteOptions - How to handle deletion.
        Returns:
        The visitation path counters.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method.
        Since:
        2.8.0
      • copyDirectory

        public static Counters.PathCounters copyDirectory​(java.nio.file.Path sourceDirectory,
                                                          java.nio.file.Path targetDirectory,
                                                          java.nio.file.CopyOption... copyOptions)
                                                   throws java.io.IOException
        Copies a directory to another directory.
        Parameters:
        sourceDirectory - The source directory.
        targetDirectory - The target directory.
        copyOptions - Specifies how the copying should be done.
        Returns:
        The visitation path counters.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method.
      • copyFile

        public static java.nio.file.Path copyFile​(java.net.URL sourceFile,
                                                  java.nio.file.Path targetFile,
                                                  java.nio.file.CopyOption... copyOptions)
                                           throws java.io.IOException
        Copies a URL to a directory.
        Parameters:
        sourceFile - The source URL.
        targetFile - The target file.
        copyOptions - Specifies how the copying should be done.
        Returns:
        The target file
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        Files.copy(InputStream, Path, CopyOption...)
      • copyFileToDirectory

        public static java.nio.file.Path copyFileToDirectory​(java.nio.file.Path sourceFile,
                                                             java.nio.file.Path targetDirectory,
                                                             java.nio.file.CopyOption... copyOptions)
                                                      throws java.io.IOException
        Copies a file to a directory.
        Parameters:
        sourceFile - The source file.
        targetDirectory - The target directory.
        copyOptions - Specifies how the copying should be done.
        Returns:
        The target file
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        Files.copy(Path, Path, CopyOption...)
      • copyFileToDirectory

        public static java.nio.file.Path copyFileToDirectory​(java.net.URL sourceFile,
                                                             java.nio.file.Path targetDirectory,
                                                             java.nio.file.CopyOption... copyOptions)
                                                      throws java.io.IOException
        Copies a URL to a directory.
        Parameters:
        sourceFile - The source URL.
        targetDirectory - The target directory.
        copyOptions - Specifies how the copying should be done.
        Returns:
        The target file
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        Files.copy(InputStream, Path, CopyOption...)
      • countDirectory

        public static Counters.PathCounters countDirectory​(java.nio.file.Path directory)
                                                    throws java.io.IOException
        Counts aspects of a directory including sub-directories.
        Parameters:
        directory - directory to delete.
        Returns:
        The visitor used to count the given directory.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method.
      • createParentDirectories

        public static java.nio.file.Path createParentDirectories​(java.nio.file.Path path,
                                                                 java.nio.file.attribute.FileAttribute<?>... attrs)
                                                          throws java.io.IOException
        Creates the parent directories for the given path.
        Parameters:
        path - The path to a file (or directory).
        attrs - An optional list of file attributes to set atomically when creating the directories.
        Returns:
        The Path for the path's parent directory or null if the given path has no parent.
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        2.9.0
      • current

        public static java.nio.file.Path current()
        Gets the current directory.
        Returns:
        the current directory.
        Since:
        2.9.0
      • delete

        public static Counters.PathCounters delete​(java.nio.file.Path path)
                                            throws java.io.IOException
        Deletes a file or directory. If the path is a directory, delete it and all sub-directories.

        The difference between File.delete() and this method are:

        • A directory to delete does not have to be empty.
        • You get exceptions when a file or directory cannot be deleted; File.delete() returns a boolean.
        Parameters:
        path - file or directory to delete, must not be null
        Returns:
        The visitor used to delete the given directory.
        Throws:
        java.lang.NullPointerException - if the directory is null
        java.io.IOException - if an I/O error is thrown by a visitor method or if an I/O error occurs.
      • delete

        public static Counters.PathCounters delete​(java.nio.file.Path path,
                                                   DeleteOption... deleteOptions)
                                            throws java.io.IOException
        Deletes a file or directory. If the path is a directory, delete it and all sub-directories.

        The difference between File.delete() and this method are:

        • A directory to delete does not have to be empty.
        • You get exceptions when a file or directory cannot be deleted; File.delete() returns a boolean.
        Parameters:
        path - file or directory to delete, must not be null
        deleteOptions - How to handle deletion.
        Returns:
        The visitor used to delete the given directory.
        Throws:
        java.lang.NullPointerException - if the directory is null
        java.io.IOException - if an I/O error is thrown by a visitor method or if an I/O error occurs.
        Since:
        2.8.0
      • delete

        public static Counters.PathCounters delete​(java.nio.file.Path path,
                                                   java.nio.file.LinkOption[] linkOptions,
                                                   DeleteOption... deleteOptions)
                                            throws java.io.IOException
        Deletes a file or directory. If the path is a directory, delete it and all sub-directories.

        The difference between File.delete() and this method are:

        • A directory to delete does not have to be empty.
        • You get exceptions when a file or directory cannot be deleted; File.delete() returns a boolean.
        Parameters:
        path - file or directory to delete, must not be null
        linkOptions - How to handle symbolic links.
        deleteOptions - How to handle deletion.
        Returns:
        The visitor used to delete the given directory.
        Throws:
        java.lang.NullPointerException - if the directory is null
        java.io.IOException - if an I/O error is thrown by a visitor method or if an I/O error occurs.
        Since:
        2.9.0
      • deleteDirectory

        public static Counters.PathCounters deleteDirectory​(java.nio.file.Path directory)
                                                     throws java.io.IOException
        Deletes a directory including sub-directories.
        Parameters:
        directory - directory to delete.
        Returns:
        The visitor used to delete the given directory.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method.
      • deleteDirectory

        public static Counters.PathCounters deleteDirectory​(java.nio.file.Path directory,
                                                            DeleteOption... deleteOptions)
                                                     throws java.io.IOException
        Deletes a directory including sub-directories.
        Parameters:
        directory - directory to delete.
        deleteOptions - How to handle deletion.
        Returns:
        The visitor used to delete the given directory.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method.
        Since:
        2.8.0
      • deleteDirectory

        public static Counters.PathCounters deleteDirectory​(java.nio.file.Path directory,
                                                            java.nio.file.LinkOption[] linkOptions,
                                                            DeleteOption... deleteOptions)
                                                     throws java.io.IOException
        Deletes a directory including sub-directories.
        Parameters:
        directory - directory to delete.
        linkOptions - How to handle symbolic links.
        deleteOptions - How to handle deletion.
        Returns:
        The visitor used to delete the given directory.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method.
        Since:
        2.9.0
      • deleteFile

        public static Counters.PathCounters deleteFile​(java.nio.file.Path file)
                                                throws java.io.IOException
        Deletes the given file.
        Parameters:
        file - The file to delete.
        Returns:
        A visitor with path counts set to 1 file, 0 directories, and the size of the deleted file.
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.nio.file.NoSuchFileException - if the file is a directory.
      • deleteFile

        public static Counters.PathCounters deleteFile​(java.nio.file.Path file,
                                                       DeleteOption... deleteOptions)
                                                throws java.io.IOException
        Deletes the given file.
        Parameters:
        file - The file to delete.
        deleteOptions - How to handle deletion.
        Returns:
        A visitor with path counts set to 1 file, 0 directories, and the size of the deleted file.
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.nio.file.NoSuchFileException - if the file is a directory.
        Since:
        2.8.0
      • deleteFile

        public static Counters.PathCounters deleteFile​(java.nio.file.Path file,
                                                       java.nio.file.LinkOption[] linkOptions,
                                                       DeleteOption... deleteOptions)
                                                throws java.nio.file.NoSuchFileException,
                                                       java.io.IOException
        Deletes the given file.
        Parameters:
        file - The file to delete.
        linkOptions - How to handle symbolic links.
        deleteOptions - How to handle deletion.
        Returns:
        A visitor with path counts set to 1 file, 0 directories, and the size of the deleted file.
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.nio.file.NoSuchFileException - if the file is a directory.
        Since:
        2.9.0
      • directoryAndFileContentEquals

        public static boolean directoryAndFileContentEquals​(java.nio.file.Path path1,
                                                            java.nio.file.Path path2)
                                                     throws java.io.IOException
        Compares the file sets of two Paths to determine if they are equal or not while considering file contents. The comparison includes all files in all sub-directories.
        Parameters:
        path1 - The first directory.
        path2 - The second directory.
        Returns:
        Whether the two directories contain the same files while considering file contents.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • directoryAndFileContentEquals

        public static boolean directoryAndFileContentEquals​(java.nio.file.Path path1,
                                                            java.nio.file.Path path2,
                                                            java.nio.file.LinkOption[] linkOptions,
                                                            java.nio.file.OpenOption[] openOptions,
                                                            java.nio.file.FileVisitOption[] fileVisitOption)
                                                     throws java.io.IOException
        Compares the file sets of two Paths to determine if they are equal or not while considering file contents. The comparison includes all files in all sub-directories.
        Parameters:
        path1 - The first directory.
        path2 - The second directory.
        linkOptions - options to follow links.
        openOptions - options to open files.
        fileVisitOption - options to configure traversal.
        Returns:
        Whether the two directories contain the same files while considering file contents.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • directoryContentEquals

        public static boolean directoryContentEquals​(java.nio.file.Path path1,
                                                     java.nio.file.Path path2)
                                              throws java.io.IOException
        Compares the file sets of two Paths to determine if they are equal or not without considering file contents. The comparison includes all files in all sub-directories.
        Parameters:
        path1 - The first directory.
        path2 - The second directory.
        Returns:
        Whether the two directories contain the same files without considering file contents.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • directoryContentEquals

        public static boolean directoryContentEquals​(java.nio.file.Path path1,
                                                     java.nio.file.Path path2,
                                                     int maxDepth,
                                                     java.nio.file.LinkOption[] linkOptions,
                                                     java.nio.file.FileVisitOption[] fileVisitOptions)
                                              throws java.io.IOException
        Compares the file sets of two Paths to determine if they are equal or not without considering file contents. The comparison includes all files in all sub-directories.
        Parameters:
        path1 - The first directory.
        path2 - The second directory.
        maxDepth - See Files.walkFileTree(Path,Set,int,FileVisitor).
        linkOptions - options to follow links.
        fileVisitOptions - options to configure the traversal
        Returns:
        Whether the two directories contain the same files without considering file contents.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • fileContentEquals

        public static boolean fileContentEquals​(java.nio.file.Path path1,
                                                java.nio.file.Path path2)
                                         throws java.io.IOException
        Compares the file contents of two Paths to determine if they are equal or not.

        File content is accessed through Files.newInputStream(Path,OpenOption...).

        Parameters:
        path1 - the first stream.
        path2 - the second stream.
        Returns:
        true if the content of the streams are equal or they both don't exist, false otherwise.
        Throws:
        java.lang.NullPointerException - if either input is null.
        java.io.IOException - if an I/O error occurs.
        See Also:
        FileUtils.contentEquals(java.io.File, java.io.File)
      • fileContentEquals

        public static boolean fileContentEquals​(java.nio.file.Path path1,
                                                java.nio.file.Path path2,
                                                java.nio.file.LinkOption[] linkOptions,
                                                java.nio.file.OpenOption[] openOptions)
                                         throws java.io.IOException
        Compares the file contents of two Paths to determine if they are equal or not.

        File content is accessed through Files.newInputStream(Path,OpenOption...).

        Parameters:
        path1 - the first stream.
        path2 - the second stream.
        linkOptions - options specifying how files are followed.
        openOptions - options specifying how files are opened.
        Returns:
        true if the content of the streams are equal or they both don't exist, false otherwise.
        Throws:
        java.lang.NullPointerException - if either input is null.
        java.io.IOException - if an I/O error occurs.
        See Also:
        FileUtils.contentEquals(java.io.File, java.io.File)
      • filter

        public static java.nio.file.Path[] filter​(PathFilter filter,
                                                  java.nio.file.Path... paths)

        Applies an IOFileFilter to the provided File objects. The resulting array is a subset of the original file list that matches the provided filter.

        The Set returned by this method is not guaranteed to be thread safe.

         Set<File> allFiles = ...
         Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
             FileFilterUtils.suffixFileFilter(".java"));
         
        Parameters:
        filter - the filter to apply to the set of files.
        paths - the array of files to apply the filter to.
        Returns:
        a subset of files that is accepted by the file filter.
        Throws:
        java.lang.IllegalArgumentException - if the filter is null or files contains a null value.
        Since:
        2.9.0
      • getAclEntryList

        public static java.util.List<java.nio.file.attribute.AclEntry> getAclEntryList​(java.nio.file.Path sourcePath)
                                                                                throws java.io.IOException
        Reads the access control list from a file attribute view.
        Parameters:
        sourcePath - the path to the file.
        Returns:
        a file attribute view of the specified type, or null if the attribute view type is not available.
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        2.8.0
      • isDirectory

        public static boolean isDirectory​(java.nio.file.Path path,
                                          java.nio.file.LinkOption... options)
        Tests whether the specified Path is a directory or not. Implemented as a null-safe delegate to Files.isDirectory(Path path, LinkOption... options).
        Parameters:
        path - the path to the file.
        options - options indicating how symbolic links are handled
        Returns:
        true if the file is a directory; false if the path is null, the file does not exist, is not a directory, or it cannot be determined if the file is a directory or not.
        Throws:
        java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the directory.
        Since:
        2.9.0
      • isEmpty

        public static boolean isEmpty​(java.nio.file.Path path)
                               throws java.io.IOException
        Tests whether the given file or directory is empty.
        Parameters:
        path - the file or directory to query.
        Returns:
        whether the file or directory is empty.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • isEmptyDirectory

        public static boolean isEmptyDirectory​(java.nio.file.Path directory)
                                        throws java.io.IOException
        Tests whether the directory is empty.
        Parameters:
        directory - the directory to query.
        Returns:
        whether the directory is empty.
        Throws:
        java.nio.file.NotDirectoryException - if the file could not otherwise be opened because it is not a directory (optional specific exception).
        java.io.IOException - if an I/O error occurs.
        java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the directory.
      • isEmptyFile

        public static boolean isEmptyFile​(java.nio.file.Path file)
                                   throws java.io.IOException
        Tests whether the given file is empty.
        Parameters:
        file - the file to query.
        Returns:
        whether the file is empty.
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.lang.SecurityException - In the case of the default provider, and a security manager is installed, its checkRead method denies read access to the file.
      • isNewer

        public static boolean isNewer​(java.nio.file.Path file,
                                      long timeMillis,
                                      java.nio.file.LinkOption... options)
                               throws java.io.IOException
        Tests if the specified Path is newer than the specified time reference.
        Parameters:
        file - the Path of which the modification date must be compared
        timeMillis - the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)
        options - options indicating how symbolic links are handled * @return true if the Path exists and has been modified after the given time reference.
        Returns:
        true if the Path exists and has been modified after the given time reference.
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.lang.NullPointerException - if the file is null
        Since:
        2.9.0
      • isRegularFile

        public static boolean isRegularFile​(java.nio.file.Path path,
                                            java.nio.file.LinkOption... options)
        Tests whether the specified Path is a regular file or not. Implemented as a null-safe delegate to Files.isRegularFile(Path path, LinkOption... options).
        Parameters:
        path - the path to the file.
        options - options indicating how symbolic links are handled
        Returns:
        true if the file is a regular file; false if the path is null, the file does not exist, is not a directory, or it cannot be determined if the file is a regular file or not.
        Throws:
        java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the directory.
        Since:
        2.9.0
      • newDirectoryStream

        public static java.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream​(java.nio.file.Path dir,
                                                                                           PathFilter pathFilter)
                                                                                    throws java.io.IOException
        Creates a new DirectoryStream for Paths rooted at the given directory.
        Parameters:
        dir - the path to the directory to stream.
        pathFilter - the directory stream filter.
        Returns:
        a new instance.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readBasicFileAttributes

        public static java.nio.file.attribute.BasicFileAttributes readBasicFileAttributes​(java.nio.file.Path path)
                                                                                   throws java.io.IOException
        Shorthand for Files.readAttributes(path, BasicFileAttributes.class)
        Parameters:
        path - the path to read.
        Returns:
        the path attributes.
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        2.9.0
      • readBasicFileAttributesUnchecked

        public static java.nio.file.attribute.BasicFileAttributes readBasicFileAttributesUnchecked​(java.nio.file.Path path)
        Shorthand for Files.readAttributes(path, BasicFileAttributes.class) while wrapping IOException as UncheckedIOException.
        Parameters:
        path - the path to read.
        Returns:
        the path attributes.
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
        Since:
        2.9.0
      • setReadOnly

        public static java.nio.file.Path setReadOnly​(java.nio.file.Path path,
                                                     boolean readOnly,
                                                     java.nio.file.LinkOption... linkOptions)
                                              throws java.io.IOException
        Sets the given Path to the readOnly value.

        This behavior is OS dependent.

        Parameters:
        path - The path to set.
        readOnly - true for read-only, false for not read-only.
        linkOptions - options indicating how symbolic links are handled.
        Returns:
        The given path.
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        2.8.0
      • visitFileTree

        public static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree​(T visitor,
                                                                                                        java.nio.file.Path directory)
                                                                                                 throws java.io.IOException
        Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor. Note that Files.walkFileTree(Path,FileVisitor) returns the given path.
        Type Parameters:
        T - See Files.walkFileTree(Path,FileVisitor).
        Parameters:
        visitor - See Files.walkFileTree(Path,FileVisitor).
        directory - See Files.walkFileTree(Path,FileVisitor).
        Returns:
        the given visitor.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • visitFileTree

        public static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree​(T visitor,
                                                                                                        java.nio.file.Path start,
                                                                                                        java.util.Set<java.nio.file.FileVisitOption> options,
                                                                                                        int maxDepth)
                                                                                                 throws java.io.IOException
        Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor. Note that Files.walkFileTree(Path,FileVisitor) returns the given path.
        Type Parameters:
        T - See Files.walkFileTree(Path,Set,int,FileVisitor).
        Parameters:
        start - See Files.walkFileTree(Path,Set,int,FileVisitor).
        options - See Files.walkFileTree(Path,Set,int,FileVisitor).
        maxDepth - See Files.walkFileTree(Path,Set,int,FileVisitor).
        visitor - See Files.walkFileTree(Path,Set,int,FileVisitor).
        Returns:
        the given visitor.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • visitFileTree

        public static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree​(T visitor,
                                                                                                        java.lang.String first,
                                                                                                        java.lang.String... more)
                                                                                                 throws java.io.IOException
        Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor. Note that Files.walkFileTree(Path,FileVisitor) returns the given path.
        Type Parameters:
        T - See Files.walkFileTree(Path,FileVisitor).
        Parameters:
        visitor - See Files.walkFileTree(Path,FileVisitor).
        first - See Paths.get(String,String[]).
        more - See Paths.get(String,String[]).
        Returns:
        the given visitor.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • visitFileTree

        public static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>> T visitFileTree​(T visitor,
                                                                                                        java.net.URI uri)
                                                                                                 throws java.io.IOException
        Performs Files.walkFileTree(Path,FileVisitor) and returns the given visitor. Note that Files.walkFileTree(Path,FileVisitor) returns the given path.
        Type Parameters:
        T - See Files.walkFileTree(Path,FileVisitor).
        Parameters:
        visitor - See Files.walkFileTree(Path,FileVisitor).
        uri - See Paths.get(URI).
        Returns:
        the given visitor.
        Throws:
        java.io.IOException - if an I/O error is thrown by a visitor method
      • walk

        public static java.util.stream.Stream<java.nio.file.Path> walk​(java.nio.file.Path start,
                                                                       PathFilter pathFilter,
                                                                       int maxDepth,
                                                                       boolean readAttributes,
                                                                       java.nio.file.FileVisitOption... options)
                                                                throws java.io.IOException
        Returns a stream of filtered paths.
        Parameters:
        start - the start path
        pathFilter - the path filter
        maxDepth - the maximum depth of directories to walk.
        readAttributes - whether to call the filters with file attributes (false passes null).
        options - the options to configure the walk.
        Returns:
        a filtered stream of paths.
        Throws:
        java.io.IOException - if an I/O error is thrown when accessing the starting file.
        Since:
        2.9.0