Package org.apache.commons.io.file
Class PathUtils
java.lang.Object
org.apache.commons.io.file.PathUtils
NIO Path utilities.
- Since:
- 2.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Private worker/holder that computes and tracks relative path names and their equality. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CopyOption[]
EmptyCopyOption
array.static final DeleteOption[]
EmptyLinkOption
array.static final FileVisitOption[]
EmptyFileVisitOption
array.static final LinkOption[]
EmptyLinkOption
array.static final OpenOption[]
EmptyOpenOption
array.static final Path[]
EmptyPath
array.static final LinkOption[]
LinkOption
array forLinkOption.NOFOLLOW_LINKS
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static AccumulatorPathVisitor
accumulate
(Path directory, int maxDepth, FileVisitOption[] fileVisitOptions) Accumulates file tree information in aAccumulatorPathVisitor
.static Counters.PathCounters
cleanDirectory
(Path directory) Cleans a directory including sub-directories without deleting directories.static Counters.PathCounters
cleanDirectory
(Path directory, DeleteOption... deleteOptions) Cleans a directory including sub-directories without deleting directories.static Counters.PathCounters
copyDirectory
(Path sourceDirectory, Path targetDirectory, CopyOption... copyOptions) Copies a directory to another directory.static Path
copyFile
(URL sourceFile, Path targetFile, CopyOption... copyOptions) Copies a URL to a directory.static Path
copyFileToDirectory
(URL sourceFile, Path targetDirectory, CopyOption... copyOptions) Copies a URL to a directory.static Path
copyFileToDirectory
(Path sourceFile, Path targetDirectory, CopyOption... copyOptions) Copies a file to a directory.static Counters.PathCounters
countDirectory
(Path directory) Counts aspects of a directory including sub-directories.static Path
createParentDirectories
(Path path, FileAttribute<?>... attrs) Creates the parent directories for the givenpath
.static Path
current()
Gets the current directory.static Counters.PathCounters
Deletes a file or directory.static Counters.PathCounters
delete
(Path path, LinkOption[] linkOptions, DeleteOption... deleteOptions) Deletes a file or directory.static Counters.PathCounters
delete
(Path path, DeleteOption... deleteOptions) Deletes a file or directory.static Counters.PathCounters
deleteDirectory
(Path directory) Deletes a directory including sub-directories.static Counters.PathCounters
deleteDirectory
(Path directory, LinkOption[] linkOptions, DeleteOption... deleteOptions) Deletes a directory including sub-directories.static Counters.PathCounters
deleteDirectory
(Path directory, DeleteOption... deleteOptions) Deletes a directory including sub-directories.static Counters.PathCounters
deleteFile
(Path file) Deletes the given file.static Counters.PathCounters
deleteFile
(Path file, LinkOption[] linkOptions, DeleteOption... deleteOptions) Deletes the given file.static Counters.PathCounters
deleteFile
(Path file, DeleteOption... deleteOptions) Deletes the given file.static boolean
directoryAndFileContentEquals
(Path path1, Path path2) Compares the file sets of two Paths to determine if they are equal or not while considering file contents.static boolean
directoryAndFileContentEquals
(Path path1, Path path2, LinkOption[] linkOptions, OpenOption[] openOptions, FileVisitOption[] fileVisitOption) Compares the file sets of two Paths to determine if they are equal or not while considering file contents.static boolean
directoryContentEquals
(Path path1, Path path2) Compares the file sets of two Paths to determine if they are equal or not without considering file contents.static boolean
directoryContentEquals
(Path path1, Path path2, int maxDepth, LinkOption[] linkOptions, FileVisitOption[] fileVisitOptions) Compares the file sets of two Paths to determine if they are equal or not without considering file contents.static boolean
fileContentEquals
(Path path1, Path path2) Compares the file contents of two Paths to determine if they are equal or not.static boolean
fileContentEquals
(Path path1, Path path2, LinkOption[] linkOptions, OpenOption[] openOptions) Compares the file contents of two Paths to determine if they are equal or not.static Path[]
filter
(PathFilter filter, Path... paths) Applies anIOFileFilter
to the providedFile
objects.private static <R,
A> R filterPaths
(PathFilter filter, Stream<Path> stream, Collector<? super Path, A, R> collector) getAclEntryList
(Path sourcePath) Reads the access control list from a file attribute view.static boolean
isDirectory
(Path path, LinkOption... options) Tests whether the specifiedPath
is a directory or not.static boolean
Tests whether the given file or directory is empty.static boolean
isEmptyDirectory
(Path directory) Tests whether the directory is empty.static boolean
isEmptyFile
(Path file) Tests whether the given file is empty.static boolean
isNewer
(Path file, long timeMillis, LinkOption... options) Tests if the specifiedPath
is newer than the specified time reference.static boolean
isRegularFile
(Path path, LinkOption... options) Tests whether the specifiedPath
is a regular file or not.static DirectoryStream<Path>
newDirectoryStream
(Path dir, PathFilter pathFilter) Creates a new DirectoryStream for Paths rooted at the given directory.private static boolean
overrideReadOnly
(DeleteOption... deleteOptions) Returns true if the given options containStandardDeleteOption.OVERRIDE_READ_ONLY
.static BasicFileAttributes
readBasicFileAttributes
(Path path) Shorthand forFiles.readAttributes(path, BasicFileAttributes.class)
static BasicFileAttributes
Shorthand forFiles.readAttributes(path, BasicFileAttributes.class)
while wrappingIOException
asUncheckedIOException
.relativize
(Collection<Path> collection, Path parent, boolean sort, Comparator<? super Path> comparator) Relativizes all files in the givencollection
against aparent
.static Path
setReadOnly
(Path path, boolean readOnly, LinkOption... linkOptions) Sets the given Path to thereadOnly
value.(package private) static Set<FileVisitOption>
toFileVisitOptionSet
(FileVisitOption... fileVisitOptions) Converts an array ofFileVisitOption
to aSet
.static <T extends FileVisitor<? super Path>>
TvisitFileTree
(T visitor, String first, String... more) PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor.static <T extends FileVisitor<? super Path>>
TvisitFileTree
(T visitor, URI uri) PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor.static <T extends FileVisitor<? super Path>>
TvisitFileTree
(T visitor, Path directory) PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor.static <T extends FileVisitor<? super Path>>
TvisitFileTree
(T visitor, Path start, Set<FileVisitOption> options, int maxDepth) PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor.walk
(Path start, PathFilter pathFilter, int maxDepth, boolean readAttributes, FileVisitOption... options) Returns a stream of filtered paths.
-
Field Details
-
EMPTY_COPY_OPTIONS
EmptyCopyOption
array.- Since:
- 2.8.0
-
EMPTY_DELETE_OPTION_ARRAY
EmptyLinkOption
array.- Since:
- 2.8.0
-
EMPTY_FILE_VISIT_OPTION_ARRAY
EmptyFileVisitOption
array. -
EMPTY_LINK_OPTION_ARRAY
EmptyLinkOption
array. -
NOFOLLOW_LINK_OPTION_ARRAY
LinkOption
array forLinkOption.NOFOLLOW_LINKS
.- Since:
- 2.9.0
-
EMPTY_OPEN_OPTION_ARRAY
EmptyOpenOption
array. -
EMPTY_PATH_ARRAY
EmptyPath
array.- Since:
- 2.9.0
-
-
Constructor Details
-
PathUtils
private PathUtils()Does allow to instantiate.
-
-
Method Details
-
accumulate
private static AccumulatorPathVisitor accumulate(Path directory, int maxDepth, FileVisitOption[] fileVisitOptions) throws IOException Accumulates file tree information in aAccumulatorPathVisitor
.- Parameters:
directory
- The directory to accumulate information.maxDepth
- SeeFiles.walkFileTree(Path,Set,int,FileVisitor)
.fileVisitOptions
- SeeFiles.walkFileTree(Path,Set,int,FileVisitor)
.- Returns:
- file tree information.
- Throws:
IOException
- if an I/O error is thrown by a visitor method.
-
cleanDirectory
Cleans a directory including sub-directories without deleting directories.- Parameters:
directory
- directory to clean.- Returns:
- The visitation path counters.
- Throws:
IOException
- if an I/O error is thrown by a visitor method.
-
cleanDirectory
public static Counters.PathCounters cleanDirectory(Path directory, DeleteOption... deleteOptions) throws 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:
IOException
- if an I/O error is thrown by a visitor method.- Since:
- 2.8.0
-
copyDirectory
public static Counters.PathCounters copyDirectory(Path sourceDirectory, Path targetDirectory, CopyOption... copyOptions) throws 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:
IOException
- if an I/O error is thrown by a visitor method.
-
copyFile
public static Path copyFile(URL sourceFile, Path targetFile, CopyOption... copyOptions) throws 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:
IOException
- if an I/O error occurs.- See Also:
-
copyFileToDirectory
public static Path copyFileToDirectory(Path sourceFile, Path targetDirectory, CopyOption... copyOptions) throws 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:
IOException
- if an I/O error occurs.- See Also:
-
copyFileToDirectory
public static Path copyFileToDirectory(URL sourceFile, Path targetDirectory, CopyOption... copyOptions) throws 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:
IOException
- if an I/O error occurs.- See Also:
-
countDirectory
Counts aspects of a directory including sub-directories.- Parameters:
directory
- directory to delete.- Returns:
- The visitor used to count the given directory.
- Throws:
IOException
- if an I/O error is thrown by a visitor method.
-
createParentDirectories
Creates the parent directories for the givenpath
.- 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:
IOException
- if an I/O error occurs.- Since:
- 2.9.0
-
current
Gets the current directory.- Returns:
- the current directory.
- Since:
- 2.9.0
-
delete
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 benull
- Returns:
- The visitor used to delete the given directory.
- Throws:
NullPointerException
- if the directory isnull
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(Path path, DeleteOption... deleteOptions) throws 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 benull
deleteOptions
- How to handle deletion.- Returns:
- The visitor used to delete the given directory.
- Throws:
NullPointerException
- if the directory isnull
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(Path path, LinkOption[] linkOptions, DeleteOption... deleteOptions) throws 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 benull
linkOptions
- How to handle symbolic links.deleteOptions
- How to handle deletion.- Returns:
- The visitor used to delete the given directory.
- Throws:
NullPointerException
- if the directory isnull
IOException
- if an I/O error is thrown by a visitor method or if an I/O error occurs.- Since:
- 2.9.0
-
deleteDirectory
Deletes a directory including sub-directories.- Parameters:
directory
- directory to delete.- Returns:
- The visitor used to delete the given directory.
- Throws:
IOException
- if an I/O error is thrown by a visitor method.
-
deleteDirectory
public static Counters.PathCounters deleteDirectory(Path directory, DeleteOption... deleteOptions) throws 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:
IOException
- if an I/O error is thrown by a visitor method.- Since:
- 2.8.0
-
deleteDirectory
public static Counters.PathCounters deleteDirectory(Path directory, LinkOption[] linkOptions, DeleteOption... deleteOptions) throws 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:
IOException
- if an I/O error is thrown by a visitor method.- Since:
- 2.9.0
-
deleteFile
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:
IOException
- if an I/O error occurs.NoSuchFileException
- if the file is a directory.
-
deleteFile
public static Counters.PathCounters deleteFile(Path file, DeleteOption... deleteOptions) throws 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:
IOException
- if an I/O error occurs.NoSuchFileException
- if the file is a directory.- Since:
- 2.8.0
-
deleteFile
public static Counters.PathCounters deleteFile(Path file, LinkOption[] linkOptions, DeleteOption... deleteOptions) throws NoSuchFileException, 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:
IOException
- if an I/O error occurs.NoSuchFileException
- if the file is a directory.- Since:
- 2.9.0
-
directoryAndFileContentEquals
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:
IOException
- if an I/O error is thrown by a visitor method
-
directoryAndFileContentEquals
public static boolean directoryAndFileContentEquals(Path path1, Path path2, LinkOption[] linkOptions, OpenOption[] openOptions, FileVisitOption[] fileVisitOption) throws 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:
IOException
- if an I/O error is thrown by a visitor method
-
directoryContentEquals
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:
IOException
- if an I/O error is thrown by a visitor method
-
directoryContentEquals
public static boolean directoryContentEquals(Path path1, Path path2, int maxDepth, LinkOption[] linkOptions, FileVisitOption[] fileVisitOptions) throws 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
- SeeFiles.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:
IOException
- if an I/O error is thrown by a visitor method
-
fileContentEquals
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:
NullPointerException
- if either input is null.IOException
- if an I/O error occurs.- See Also:
-
fileContentEquals
public static boolean fileContentEquals(Path path1, Path path2, LinkOption[] linkOptions, OpenOption[] openOptions) throws 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:
NullPointerException
- if either input is null.IOException
- if an I/O error occurs.- See Also:
-
filter
Applies an
IOFileFilter
to the providedFile
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:
IllegalArgumentException
- if the filter isnull
orfiles
contains anull
value.- Since:
- 2.9.0
-
filterPaths
private static <R,A> R filterPaths(PathFilter filter, Stream<Path> stream, Collector<? super Path, A, R> collector) -
getAclEntryList
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:
IOException
- if an I/O error occurs.- Since:
- 2.8.0
-
isDirectory
Tests whether the specifiedPath
is a directory or not. Implemented as a null-safe delegate toFiles.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:
SecurityException
- In the case of the default provider, and a security manager is installed, thecheckRead
method is invoked to check read access to the directory.- Since:
- 2.9.0
-
isEmpty
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:
IOException
- if an I/O error occurs.
-
isEmptyDirectory
Tests whether the directory is empty.- Parameters:
directory
- the directory to query.- Returns:
- whether the directory is empty.
- Throws:
NotDirectoryException
- if the file could not otherwise be opened because it is not a directory (optional specific exception).IOException
- if an I/O error occurs.SecurityException
- In the case of the default provider, and a security manager is installed, thecheckRead
method is invoked to check read access to the directory.
-
isEmptyFile
Tests whether the given file is empty.- Parameters:
file
- the file to query.- Returns:
- whether the file is empty.
- Throws:
IOException
- if an I/O error occurs.SecurityException
- In the case of the default provider, and a security manager is installed, itscheckRead
method denies read access to the file.
-
isNewer
Tests if the specifiedPath
is newer than the specified time reference.- Parameters:
file
- thePath
of which the modification date must be comparedtimeMillis
- 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 thePath
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:
IOException
- if an I/O error occurs.NullPointerException
- if the file isnull
- Since:
- 2.9.0
-
isRegularFile
Tests whether the specifiedPath
is a regular file or not. Implemented as a null-safe delegate toFiles.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:
SecurityException
- In the case of the default provider, and a security manager is installed, thecheckRead
method is invoked to check read access to the directory.- Since:
- 2.9.0
-
newDirectoryStream
public static DirectoryStream<Path> newDirectoryStream(Path dir, PathFilter pathFilter) throws 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:
IOException
- if an I/O error occurs.
-
overrideReadOnly
Returns true if the given options containStandardDeleteOption.OVERRIDE_READ_ONLY
.- Parameters:
deleteOptions
- the array to test- Returns:
- true if the given options contain
StandardDeleteOption.OVERRIDE_READ_ONLY
.
-
readBasicFileAttributes
Shorthand forFiles.readAttributes(path, BasicFileAttributes.class)
- Parameters:
path
- the path to read.- Returns:
- the path attributes.
- Throws:
IOException
- if an I/O error occurs.- Since:
- 2.9.0
-
readBasicFileAttributesUnchecked
Shorthand forFiles.readAttributes(path, BasicFileAttributes.class)
while wrappingIOException
asUncheckedIOException
.- Parameters:
path
- the path to read.- Returns:
- the path attributes.
- Throws:
UncheckedIOException
- if an I/O error occurs- Since:
- 2.9.0
-
relativize
static List<Path> relativize(Collection<Path> collection, Path parent, boolean sort, Comparator<? super Path> comparator) Relativizes all files in the givencollection
against aparent
.- Parameters:
collection
- The collection of paths to relativize.parent
- relativizes against this parent path.sort
- Whether to sort the result.comparator
- How to sort.- Returns:
- A collection of relativized paths, optionally sorted.
-
setReadOnly
public static Path setReadOnly(Path path, boolean readOnly, LinkOption... linkOptions) throws IOException Sets the given Path to thereadOnly
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:
IOException
- if an I/O error occurs.- Since:
- 2.8.0
-
toFileVisitOptionSet
Converts an array ofFileVisitOption
to aSet
.- Parameters:
fileVisitOptions
- input array.- Returns:
- a new Set.
-
visitFileTree
public static <T extends FileVisitor<? super Path>> T visitFileTree(T visitor, Path directory) throws IOException PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor. Note thatFiles.walkFileTree(Path,FileVisitor)
returns the given path.- Type Parameters:
T
- SeeFiles.walkFileTree(Path,FileVisitor)
.- Parameters:
visitor
- SeeFiles.walkFileTree(Path,FileVisitor)
.directory
- SeeFiles.walkFileTree(Path,FileVisitor)
.- Returns:
- the given visitor.
- Throws:
IOException
- if an I/O error is thrown by a visitor method
-
visitFileTree
public static <T extends FileVisitor<? super Path>> T visitFileTree(T visitor, Path start, Set<FileVisitOption> options, int maxDepth) throws IOException PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor. Note thatFiles.walkFileTree(Path,FileVisitor)
returns the given path.- Type Parameters:
T
- SeeFiles.walkFileTree(Path,Set,int,FileVisitor)
.- Parameters:
start
- SeeFiles.walkFileTree(Path,Set,int,FileVisitor)
.options
- SeeFiles.walkFileTree(Path,Set,int,FileVisitor)
.maxDepth
- SeeFiles.walkFileTree(Path,Set,int,FileVisitor)
.visitor
- SeeFiles.walkFileTree(Path,Set,int,FileVisitor)
.- Returns:
- the given visitor.
- Throws:
IOException
- if an I/O error is thrown by a visitor method
-
visitFileTree
public static <T extends FileVisitor<? super Path>> T visitFileTree(T visitor, String first, String... more) throws IOException PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor. Note thatFiles.walkFileTree(Path,FileVisitor)
returns the given path.- Type Parameters:
T
- SeeFiles.walkFileTree(Path,FileVisitor)
.- Parameters:
visitor
- SeeFiles.walkFileTree(Path,FileVisitor)
.first
- SeePaths.get(String,String[])
.more
- SeePaths.get(String,String[])
.- Returns:
- the given visitor.
- Throws:
IOException
- if an I/O error is thrown by a visitor method
-
visitFileTree
public static <T extends FileVisitor<? super Path>> T visitFileTree(T visitor, URI uri) throws IOException PerformsFiles.walkFileTree(Path,FileVisitor)
and returns the given visitor. Note thatFiles.walkFileTree(Path,FileVisitor)
returns the given path.- Type Parameters:
T
- SeeFiles.walkFileTree(Path,FileVisitor)
.- Parameters:
visitor
- SeeFiles.walkFileTree(Path,FileVisitor)
.uri
- SeePaths.get(URI)
.- Returns:
- the given visitor.
- Throws:
IOException
- if an I/O error is thrown by a visitor method
-
walk
public static Stream<Path> walk(Path start, PathFilter pathFilter, int maxDepth, boolean readAttributes, FileVisitOption... options) throws IOException Returns a stream of filtered paths.- Parameters:
start
- the start pathpathFilter
- the path filtermaxDepth
- 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:
IOException
- if an I/O error is thrown when accessing the starting file.- Since:
- 2.9.0
-