Class PathUtils
- java.lang.Object
 - 
- org.apache.commons.io.file.PathUtils
 
 
- 
public final class PathUtils extends java.lang.ObjectNIO Path utilities.- Since:
 - 2.7
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static java.nio.file.CopyOption[]EMPTY_COPY_OPTIONSEmptyCopyOptionarray.static DeleteOption[]EMPTY_DELETE_OPTION_ARRAYEmptyDeleteOptionarray.static java.nio.file.attribute.FileAttribute<?>[]EMPTY_FILE_ATTRIBUTE_ARRAYEmptyFileAttributearray.static java.nio.file.FileVisitOption[]EMPTY_FILE_VISIT_OPTION_ARRAYEmptyFileVisitOptionarray.static java.nio.file.LinkOption[]EMPTY_LINK_OPTION_ARRAYEmptyLinkOptionarray.static java.nio.file.OpenOption[]EMPTY_OPEN_OPTION_ARRAYEmptyOpenOptionarray.static java.nio.file.Path[]EMPTY_PATH_ARRAYEmptyPatharray.static java.nio.file.LinkOption[]NOFOLLOW_LINK_OPTION_ARRAYDeprecated. 
- 
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Counters.PathCounterscleanDirectory(java.nio.file.Path directory)Cleans a directory including subdirectories without deleting directories.static Counters.PathCounterscleanDirectory(java.nio.file.Path directory, DeleteOption... deleteOptions)Cleans a directory including subdirectories without deleting directories.static longcopy(IOSupplier<java.io.InputStream> in, java.nio.file.Path target, java.nio.file.CopyOption... copyOptions)Copies the InputStream from the supplier withFiles.copy(InputStream, Path, CopyOption...).static Counters.PathCounterscopyDirectory(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.PathcopyFile(java.net.URL sourceFile, java.nio.file.Path targetFile, java.nio.file.CopyOption... copyOptions)Copies a URL to a directory.static java.nio.file.PathcopyFileToDirectory(java.net.URL sourceFile, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)Copies a URL to a directory.static java.nio.file.PathcopyFileToDirectory(java.nio.file.Path sourceFile, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)Copies a file to a directory.static Counters.PathCounterscountDirectory(java.nio.file.Path directory)Counts aspects of a directory including subdirectories.static Counters.PathCounterscountDirectoryAsBigInteger(java.nio.file.Path directory)Counts aspects of a directory including subdirectories.static java.nio.file.PathcreateParentDirectories(java.nio.file.Path path, java.nio.file.attribute.FileAttribute<?>... attrs)Creates the parent directories for the givenpath.static java.nio.file.PathcreateParentDirectories(java.nio.file.Path path, java.nio.file.LinkOption linkOption, java.nio.file.attribute.FileAttribute<?>... attrs)Creates the parent directories for the givenpath.static java.nio.file.Pathcurrent()Gets the current directory.static Counters.PathCountersdelete(java.nio.file.Path path)Deletes a file or directory.static Counters.PathCountersdelete(java.nio.file.Path path, java.nio.file.LinkOption[] linkOptions, DeleteOption... deleteOptions)Deletes a file or directory.static Counters.PathCountersdelete(java.nio.file.Path path, DeleteOption... deleteOptions)Deletes a file or directory.static Counters.PathCountersdeleteDirectory(java.nio.file.Path directory)Deletes a directory including subdirectories.static Counters.PathCountersdeleteDirectory(java.nio.file.Path directory, java.nio.file.LinkOption[] linkOptions, DeleteOption... deleteOptions)Deletes a directory including subdirectories.static Counters.PathCountersdeleteDirectory(java.nio.file.Path directory, DeleteOption... deleteOptions)Deletes a directory including subdirectories.static Counters.PathCountersdeleteFile(java.nio.file.Path file)Deletes the given file.static Counters.PathCountersdeleteFile(java.nio.file.Path file, java.nio.file.LinkOption[] linkOptions, DeleteOption... deleteOptions)Deletes the given file.static Counters.PathCountersdeleteFile(java.nio.file.Path file, DeleteOption... deleteOptions)Deletes the given file.static voiddeleteOnExit(java.nio.file.Path path)Delegates toFile.deleteOnExit().static booleandirectoryAndFileContentEquals(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 booleandirectoryAndFileContentEquals(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 booleandirectoryContentEquals(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 booleandirectoryContentEquals(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 booleanfileContentEquals(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 booleanfileContentEquals(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 anIOFileFilterto the providedFileobjects.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 java.nio.file.attribute.AclFileAttributeViewgetAclFileAttributeView(java.nio.file.Path path, java.nio.file.LinkOption... options)Shorthand forFiles.getFileAttributeView(path, AclFileAttributeView.class).static java.lang.StringgetBaseName(java.nio.file.Path path)Gets the base name (the part up to and not including the last ".") of the last path segment of a file name.static java.nio.file.attribute.DosFileAttributeViewgetDosFileAttributeView(java.nio.file.Path path, java.nio.file.LinkOption... options)Shorthand forFiles.getFileAttributeView(path, DosFileAttributeView.class).static java.lang.StringgetExtension(java.nio.file.Path path)Gets the extension of a Path.static <R> RgetFileName(java.nio.file.Path path, java.util.function.Function<java.nio.file.Path,R> function)Gets the Path's file name and apply the given function if the file name is non-null.static java.lang.StringgetFileNameString(java.nio.file.Path path)Gets the Path's file name as a string.static java.nio.file.attribute.FileTimegetLastModifiedFileTime(java.io.File file)Gets the file's last modified time or null if the file does not exist.static java.nio.file.attribute.FileTimegetLastModifiedFileTime(java.net.URI uri)Gets the file's last modified time or null if the file does not exist.static java.nio.file.attribute.FileTimegetLastModifiedFileTime(java.net.URL url)Gets the file's last modified time or null if the file does not exist.static java.nio.file.attribute.FileTimegetLastModifiedFileTime(java.nio.file.Path path, java.nio.file.attribute.FileTime defaultIfAbsent, java.nio.file.LinkOption... options)Gets the file's last modified time or null if the file does not exist.static java.nio.file.attribute.FileTimegetLastModifiedFileTime(java.nio.file.Path path, java.nio.file.LinkOption... options)Gets the file's last modified time or null if the file does not exist.static java.nio.file.attribute.PosixFileAttributeViewgetPosixFileAttributeView(java.nio.file.Path path, java.nio.file.LinkOption... options)Shorthand forFiles.getFileAttributeView(path, PosixFileAttributeView.class).static java.nio.file.PathgetTempDirectory()Gets aPathrepresenting the system temporary directory.static booleanisDirectory(java.nio.file.Path path, java.nio.file.LinkOption... options)Tests whether the givenPathis a directory or not.static booleanisEmpty(java.nio.file.Path path)Tests whether the given file or directory is empty.static booleanisEmptyDirectory(java.nio.file.Path directory)Tests whether the directory is empty.static booleanisEmptyFile(java.nio.file.Path file)Tests whether the given file is empty.static booleanisNewer(java.nio.file.Path file, long timeMillis, java.nio.file.LinkOption... options)Tests if the givenPathis newer than the given time reference.static booleanisNewer(java.nio.file.Path file, java.nio.file.attribute.FileTime fileTime, java.nio.file.LinkOption... options)Tests if the givenPathis newer than the given time reference.static booleanisNewer(java.nio.file.Path file, java.nio.file.Path reference)Tests if the givenPathis newer than the referencePath.static booleanisNewer(java.nio.file.Path file, java.time.chrono.ChronoZonedDateTime<?> czdt, java.nio.file.LinkOption... options)Tests if the givenPathis newer than the given time reference.static booleanisNewer(java.nio.file.Path file, java.time.Instant instant, java.nio.file.LinkOption... options)Tests if the givenPathis newer than the given time reference.static booleanisOlder(java.nio.file.Path file, long timeMillis, java.nio.file.LinkOption... options)Tests if the givenPathis older than the given time reference.static booleanisOlder(java.nio.file.Path file, java.nio.file.attribute.FileTime fileTime, java.nio.file.LinkOption... options)Tests if the givenPathis older than the given time reference.static booleanisOlder(java.nio.file.Path file, java.nio.file.Path reference)Tests if the givenPathis older than the referencePath.static booleanisOlder(java.nio.file.Path file, java.time.Instant instant, java.nio.file.LinkOption... options)Tests if the givenPathis older than the given time reference.static booleanisPosix(java.nio.file.Path test, java.nio.file.LinkOption... options)Tests whether the given path is on a POSIX file system.static booleanisRegularFile(java.nio.file.Path path, java.nio.file.LinkOption... options)Tests whether the givenPathis 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.io.OutputStreamnewOutputStream(java.nio.file.Path path, boolean append)Creates a new OutputStream by opening or creating a file, returning an output stream that may be used to write bytes to the file.static java.nio.file.LinkOption[]noFollowLinkOptionArray()Copy of theLinkOptionarray forLinkOption.NOFOLLOW_LINKS.static <A extends java.nio.file.attribute.BasicFileAttributes>
AreadAttributes(java.nio.file.Path path, java.lang.Class<A> type, java.nio.file.LinkOption... options)Reads the BasicFileAttributes from the given path.static java.nio.file.attribute.BasicFileAttributesreadBasicFileAttributes(java.nio.file.Path path)Reads the BasicFileAttributes from the given path.static java.nio.file.attribute.BasicFileAttributesreadBasicFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the BasicFileAttributes from the given path.static java.nio.file.attribute.BasicFileAttributesreadBasicFileAttributesUnchecked(java.nio.file.Path path)Deprecated.static java.nio.file.attribute.DosFileAttributesreadDosFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the DosFileAttributes from the given path.static java.nio.file.attribute.BasicFileAttributesreadOsFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the PosixFileAttributes or DosFileAttributes from the given path.static java.nio.file.attribute.PosixFileAttributesreadPosixFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the PosixFileAttributes from the given path.static java.lang.StringreadString(java.nio.file.Path path, java.nio.charset.Charset charset)Reads the given path as a String.static voidsetLastModifiedTime(java.nio.file.Path sourceFile, java.nio.file.Path targetFile)Sets the giventargetFile's last modified time to the value fromsourceFile.static java.nio.file.PathsetReadOnly(java.nio.file.Path path, boolean readOnly, java.nio.file.LinkOption... linkOptions)Sets the given Path to thereadOnlyvalue.static longsizeOf(java.nio.file.Path path)Returns the size of the given file or directory.static java.math.BigIntegersizeOfAsBigInteger(java.nio.file.Path path)Returns the size of the given file or directory.static longsizeOfDirectory(java.nio.file.Path directory)Counts the size of a directory recursively (sum of the size of all files).static java.math.BigIntegersizeOfDirectoryAsBigInteger(java.nio.file.Path directory)Counts the size of a directory recursively (sum of the size of all files).static java.nio.file.Pathtouch(java.nio.file.Path file)Implements behavior similar to the UNIX "touch" utility.static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
TvisitFileTree(T visitor, java.lang.String first, java.lang.String... more)PerformsFiles.walkFileTree(Path,FileVisitor)and returns the given visitor.static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
TvisitFileTree(T visitor, java.net.URI uri)PerformsFiles.walkFileTree(Path,FileVisitor)and returns the given visitor.static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
TvisitFileTree(T visitor, java.nio.file.Path directory)PerformsFiles.walkFileTree(Path,FileVisitor)and returns the given visitor.static <T extends java.nio.file.FileVisitor<? super java.nio.file.Path>>
TvisitFileTree(T visitor, java.nio.file.Path start, java.util.Set<java.nio.file.FileVisitOption> options, int maxDepth)PerformsFiles.walkFileTree(Path,FileVisitor)and returns the given visitor.static booleanwaitFor(java.nio.file.Path file, java.time.Duration timeout, java.nio.file.LinkOption... options)Waits for the file system to propagate a file creation, with a timeout.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.static java.nio.file.PathwriteString(java.nio.file.Path path, java.lang.CharSequence charSequence, java.nio.charset.Charset charset, java.nio.file.OpenOption... openOptions)Writes the given character sequence to a file at the given path. 
 - 
 
- 
- 
Field Detail
- 
EMPTY_COPY_OPTIONS
public static final java.nio.file.CopyOption[] EMPTY_COPY_OPTIONS
EmptyCopyOptionarray.- Since:
 - 2.8.0
 
 
- 
EMPTY_DELETE_OPTION_ARRAY
public static final DeleteOption[] EMPTY_DELETE_OPTION_ARRAY
EmptyDeleteOptionarray.- Since:
 - 2.8.0
 
 
- 
EMPTY_FILE_ATTRIBUTE_ARRAY
public static final java.nio.file.attribute.FileAttribute<?>[] EMPTY_FILE_ATTRIBUTE_ARRAY
EmptyFileAttributearray.- Since:
 - 2.13.0
 
 
- 
EMPTY_FILE_VISIT_OPTION_ARRAY
public static final java.nio.file.FileVisitOption[] EMPTY_FILE_VISIT_OPTION_ARRAY
EmptyFileVisitOptionarray. 
- 
EMPTY_LINK_OPTION_ARRAY
public static final java.nio.file.LinkOption[] EMPTY_LINK_OPTION_ARRAY
EmptyLinkOptionarray. 
- 
NOFOLLOW_LINK_OPTION_ARRAY
@Deprecated public static final java.nio.file.LinkOption[] NOFOLLOW_LINK_OPTION_ARRAY
Deprecated.LinkOptionarray forLinkOption.NOFOLLOW_LINKS.- Since:
 - 2.9.0
 
 
- 
EMPTY_OPEN_OPTION_ARRAY
public static final java.nio.file.OpenOption[] EMPTY_OPEN_OPTION_ARRAY
EmptyOpenOptionarray. 
- 
EMPTY_PATH_ARRAY
public static final java.nio.file.Path[] EMPTY_PATH_ARRAY
EmptyPatharray.- 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 subdirectories 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 subdirectories 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
 
 
- 
copy
public static long copy(IOSupplier<java.io.InputStream> in, java.nio.file.Path target, java.nio.file.CopyOption... copyOptions) throws java.io.IOException
Copies the InputStream from the supplier withFiles.copy(InputStream, Path, CopyOption...).- Parameters:
 in- Supplies the InputStream.target- SeeFiles.copy(InputStream, Path, CopyOption...).copyOptions- SeeFiles.copy(InputStream, Path, CopyOption...).- Returns:
 - See 
Files.copy(InputStream, Path, CopyOption...) - Throws:
 java.io.IOException- SeeFiles.copy(InputStream, Path, CopyOption...)- Since:
 - 2.12.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.IOExceptionCopies 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.IOExceptionCopies 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.IOExceptionCopies 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 subdirectories.- 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.
 
- 
countDirectoryAsBigInteger
public static Counters.PathCounters countDirectoryAsBigInteger(java.nio.file.Path directory) throws java.io.IOException
Counts aspects of a directory including subdirectories.- Parameters:
 directory- directory to count.- Returns:
 - The visitor used to count the given directory.
 - Throws:
 java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
createParentDirectories
public static java.nio.file.Path createParentDirectories(java.nio.file.Path path, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOExceptionCreates the parent directories for the givenpath.If the parent directory already exists, then return it.
- 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
 
 
- 
createParentDirectories
public static java.nio.file.Path createParentDirectories(java.nio.file.Path path, java.nio.file.LinkOption linkOption, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOExceptionCreates the parent directories for the givenpath.If the parent directory already exists, then return it.
- Parameters:
 path- The path to a file (or directory).linkOption- ALinkOptionor null.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.12.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 subdirectories.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:
 java.lang.NullPointerException- if the directory isnulljava.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 subdirectories.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 benulldeleteOptions- How to handle deletion.- Returns:
 - The visitor used to delete the given directory.
 - Throws:
 java.lang.NullPointerException- if the directory isnulljava.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 subdirectories.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 benulllinkOptions- 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 isnulljava.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 subdirectories.- 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 subdirectories.- 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 subdirectories.- 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
 
 
- 
deleteOnExit
public static void deleteOnExit(java.nio.file.Path path)
Delegates toFile.deleteOnExit().- Parameters:
 path- the path to delete.- Since:
 - 3.13.0
 
 
- 
directoryAndFileContentEquals
public static boolean directoryAndFileContentEquals(java.nio.file.Path path1, java.nio.file.Path path2) throws java.io.IOExceptionCompares 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 subdirectories.- 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.IOExceptionCompares 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 subdirectories.- 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.IOExceptionCompares 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 subdirectories.- 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.IOExceptionCompares 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 subdirectories.- 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:
 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.IOExceptionCompares 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.IOExceptionCompares the file contents of two Paths to determine if they are equal or not.File content is accessed through
RandomAccessFileMode.create(Path).- Parameters:
 path1- the first stream.path2- the second stream.linkOptions- options specifying how files are followed.openOptions- ignored.- Returns:
 - true if the content of the streams are equal or they both don't exist, false otherwise.
 - Throws:
 java.lang.NullPointerException- if openOptions 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
IOFileFilterto the providedFileobjects. The resulting array is a subset of the original file list that matches the provided filter.The
Setreturned 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 
filesthat is accepted by the file filter. - Throws:
 java.lang.NullPointerException- if the filter isnulljava.lang.IllegalArgumentException- iffilescontains anullvalue.- Since:
 - 2.9.0
 
 
- 
getAclEntryList
public static java.util.List<java.nio.file.attribute.AclEntry> getAclEntryList(java.nio.file.Path sourcePath) throws java.io.IOExceptionReads the access control list from a file attribute view.- Parameters:
 sourcePath- the path to the file.- Returns:
 - a file attribute view of the given 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
 
 
- 
getAclFileAttributeView
public static java.nio.file.attribute.AclFileAttributeView getAclFileAttributeView(java.nio.file.Path path, java.nio.file.LinkOption... options)Shorthand forFiles.getFileAttributeView(path, AclFileAttributeView.class).- Parameters:
 path- the path to the file.options- how to handle symbolic links.- Returns:
 - a AclFileAttributeView, or 
nullif the attribute view type is not available. - Since:
 - 2.12.0
 
 
- 
getBaseName
public static java.lang.String getBaseName(java.nio.file.Path path)
Gets the base name (the part up to and not including the last ".") of the last path segment of a file name.Will return the file name itself if it doesn't contain any dots. All leading directories of the
file nameparameter are skipped.- Parameters:
 path- the path of the file to obtain the base name of.- Returns:
 - the base name of file name
 - Since:
 - 2.16.0
 
 
- 
getDosFileAttributeView
public static java.nio.file.attribute.DosFileAttributeView getDosFileAttributeView(java.nio.file.Path path, java.nio.file.LinkOption... options)Shorthand forFiles.getFileAttributeView(path, DosFileAttributeView.class).- Parameters:
 path- the path to the file.options- how to handle symbolic links.- Returns:
 - a DosFileAttributeView, or 
nullif the attribute view type is not available. - Since:
 - 2.12.0
 
 
- 
getExtension
public static java.lang.String getExtension(java.nio.file.Path path)
Gets the extension of a Path.This method returns the textual part of the Path after the last dot.
foo.txt --> "txt" a/b/c.jpg --> "jpg" a/b.txt/c --> "" a/b/c --> ""
The output will be the same irrespective of the machine that the code is running on.
- Parameters:
 path- the path to query.- Returns:
 - the extension of the file or an empty string if none exists or 
nullif the fileName isnull. - Since:
 - 2.16.0
 
 
- 
getFileName
public static <R> R getFileName(java.nio.file.Path path, java.util.function.Function<java.nio.file.Path,R> function)Gets the Path's file name and apply the given function if the file name is non-null.- Type Parameters:
 R- The function's result type.- Parameters:
 path- the path to query.function- function to apply to the file name.- Returns:
 - the Path's file name as a string or null.
 - Since:
 - 2.16.0
 - See Also:
 Path.getFileName()
 
- 
getFileNameString
public static java.lang.String getFileNameString(java.nio.file.Path path)
Gets the Path's file name as a string.- Parameters:
 path- the path to query.- Returns:
 - the Path's file name as a string or null.
 - Since:
 - 2.16.0
 - See Also:
 Path.getFileName()
 
- 
getLastModifiedFileTime
public static java.nio.file.attribute.FileTime getLastModifiedFileTime(java.io.File file) throws java.io.IOExceptionGets the file's last modified time or null if the file does not exist.The method provides a workaround for bug JDK-8177809 where
File.lastModified()looses milliseconds and always ends in 000. This bug is in OpenJDK 8 and 9, and fixed in 11.- Parameters:
 file- the file to query.- Returns:
 - the file's last modified time.
 - Throws:
 java.io.IOException- Thrown if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
getLastModifiedFileTime
public static java.nio.file.attribute.FileTime getLastModifiedFileTime(java.nio.file.Path path, java.nio.file.attribute.FileTime defaultIfAbsent, java.nio.file.LinkOption... options) throws java.io.IOExceptionGets the file's last modified time or null if the file does not exist.- Parameters:
 path- the file to query.defaultIfAbsent- Returns this file time of the file does not exist, may be null.options- options indicating how symbolic links are handled.- Returns:
 - the file's last modified time.
 - Throws:
 java.io.IOException- Thrown if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
getLastModifiedFileTime
public static java.nio.file.attribute.FileTime getLastModifiedFileTime(java.nio.file.Path path, java.nio.file.LinkOption... options) throws java.io.IOExceptionGets the file's last modified time or null if the file does not exist.- Parameters:
 path- the file to query.options- options indicating how symbolic links are handled.- Returns:
 - the file's last modified time.
 - Throws:
 java.io.IOException- Thrown if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
getLastModifiedFileTime
public static java.nio.file.attribute.FileTime getLastModifiedFileTime(java.net.URI uri) throws java.io.IOExceptionGets the file's last modified time or null if the file does not exist.- Parameters:
 uri- the file to query.- Returns:
 - the file's last modified time.
 - Throws:
 java.io.IOException- Thrown if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
getLastModifiedFileTime
public static java.nio.file.attribute.FileTime getLastModifiedFileTime(java.net.URL url) throws java.io.IOException, java.net.URISyntaxExceptionGets the file's last modified time or null if the file does not exist.- Parameters:
 url- the file to query.- Returns:
 - the file's last modified time.
 - Throws:
 java.io.IOException- Thrown if an I/O error occurs.java.net.URISyntaxException- if the URL is not formatted strictly according to RFC2396 and cannot be converted to a URI.- Since:
 - 2.12.0
 
 
- 
getPosixFileAttributeView
public static java.nio.file.attribute.PosixFileAttributeView getPosixFileAttributeView(java.nio.file.Path path, java.nio.file.LinkOption... options)Shorthand forFiles.getFileAttributeView(path, PosixFileAttributeView.class).- Parameters:
 path- the path to the file.options- how to handle symbolic links.- Returns:
 - a PosixFileAttributeView, or 
nullif the attribute view type is not available. - Since:
 - 2.12.0
 
 
- 
getTempDirectory
public static java.nio.file.Path getTempDirectory()
Gets aPathrepresenting the system temporary directory.- Returns:
 - the system temporary directory.
 - Since:
 - 2.12.0
 
 
- 
isDirectory
public static boolean isDirectory(java.nio.file.Path path, java.nio.file.LinkOption... options)Tests whether the givenPathis 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 to handle symbolic links- Returns:
 trueif the file is a directory;falseif 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, thecheckReadmethod 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.IOExceptionTests 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.IOExceptionTests 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, thecheckReadmethod is invoked to check read access to the directory.
 
- 
isEmptyFile
public static boolean isEmptyFile(java.nio.file.Path file) throws java.io.IOExceptionTests 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, itscheckReadmethod denies read access to the file.
 
- 
isNewer
public static boolean isNewer(java.nio.file.Path file, java.time.chrono.ChronoZonedDateTime<?> czdt, java.nio.file.LinkOption... options) throws java.io.IOExceptionTests if the givenPathis newer than the given time reference.- Parameters:
 file- thePathto test.czdt- the time reference.options- options indicating how to handle symbolic links.- Returns:
 - true if the 
Pathexists 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 isnull.- Since:
 - 2.12.0
 
 
- 
isNewer
public static boolean isNewer(java.nio.file.Path file, java.nio.file.attribute.FileTime fileTime, java.nio.file.LinkOption... options) throws java.io.IOExceptionTests if the givenPathis newer than the given time reference.- Parameters:
 file- thePathto test.fileTime- the time reference.options- options indicating how to handle symbolic links.- Returns:
 - true if the 
Pathexists 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 isnull.- Since:
 - 2.12.0
 
 
- 
isNewer
public static boolean isNewer(java.nio.file.Path file, java.time.Instant instant, java.nio.file.LinkOption... options) throws java.io.IOExceptionTests if the givenPathis newer than the given time reference.- Parameters:
 file- thePathto test.instant- the time reference.options- options indicating how to handle symbolic links.- Returns:
 - true if the 
Pathexists 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 isnull.- Since:
 - 2.12.0
 
 
- 
isNewer
public static boolean isNewer(java.nio.file.Path file, long timeMillis, java.nio.file.LinkOption... options) throws java.io.IOExceptionTests if the givenPathis newer than the given time reference.- Parameters:
 file- thePathto test.timeMillis- the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)options- options indicating how to handle symbolic links.- Returns:
 - true if the 
Pathexists 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 isnull.- Since:
 - 2.9.0
 
 
- 
isNewer
public static boolean isNewer(java.nio.file.Path file, java.nio.file.Path reference) throws java.io.IOExceptionTests if the givenPathis newer than the referencePath.- Parameters:
 file- theFileto test.reference- theFileof which the modification date is used.- Returns:
 - true if the 
Fileexists and has been modified more recently than the referenceFile. - Throws:
 java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
isOlder
public static boolean isOlder(java.nio.file.Path file, java.nio.file.attribute.FileTime fileTime, java.nio.file.LinkOption... options) throws java.io.IOExceptionTests if the givenPathis older than the given time reference.- Parameters:
 file- thePathto test.fileTime- the time reference.options- options indicating how to handle symbolic links.- Returns:
 - true if the 
Pathexists and has been modified before the given time reference. - Throws:
 java.io.IOException- if an I/O error occurs.java.lang.NullPointerException- if the file isnull.- Since:
 - 2.12.0
 
 
- 
isOlder
public static boolean isOlder(java.nio.file.Path file, java.time.Instant instant, java.nio.file.LinkOption... options) throws java.io.IOExceptionTests if the givenPathis older than the given time reference.- Parameters:
 file- thePathto test.instant- the time reference.options- options indicating how to handle symbolic links.- Returns:
 - true if the 
Pathexists and has been modified before the given time reference. - Throws:
 java.io.IOException- if an I/O error occurs.java.lang.NullPointerException- if the file isnull.- Since:
 - 2.12.0
 
 
- 
isOlder
public static boolean isOlder(java.nio.file.Path file, long timeMillis, java.nio.file.LinkOption... options) throws java.io.IOExceptionTests if the givenPathis older than the given time reference.- Parameters:
 file- thePathto test.timeMillis- the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)options- options indicating how to handle symbolic links.- Returns:
 - true if the 
Pathexists and has been modified before the given time reference. - Throws:
 java.io.IOException- if an I/O error occurs.java.lang.NullPointerException- if the file isnull.- Since:
 - 2.12.0
 
 
- 
isOlder
public static boolean isOlder(java.nio.file.Path file, java.nio.file.Path reference) throws java.io.IOExceptionTests if the givenPathis older than the referencePath.- Parameters:
 file- theFileto test.reference- theFileof which the modification date is used.- Returns:
 - true if the 
Fileexists and has been modified before than the referenceFile. - Throws:
 java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
isPosix
public static boolean isPosix(java.nio.file.Path test, java.nio.file.LinkOption... options)Tests whether the given path is on a POSIX file system.- Parameters:
 test- The Path to test.options- options indicating how to handle symbolic links.- Returns:
 - true if test is on a POSIX file system.
 - Since:
 - 2.12.0
 
 
- 
isRegularFile
public static boolean isRegularFile(java.nio.file.Path path, java.nio.file.LinkOption... options)Tests whether the givenPathis 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 to handle symbolic links.- Returns:
 trueif the file is a regular file;falseif 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, thecheckReadmethod 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.IOExceptionCreates a new DirectoryStream for Paths rooted at the given directory.If you don't use the try-with-resources construct, then you must call the stream's
BaseStream.close()method after iteration is complete to free any resources held for the open 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.
 
- 
newOutputStream
public static java.io.OutputStream newOutputStream(java.nio.file.Path path, boolean append) throws java.io.IOExceptionCreates a new OutputStream by opening or creating a file, returning an output stream that may be used to write bytes to the file.- Parameters:
 path- the Path.append- Whether or not to append.- Returns:
 - a new OutputStream.
 - Throws:
 java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 - See Also:
 Files.newOutputStream(Path, OpenOption...)
 
- 
noFollowLinkOptionArray
public static java.nio.file.LinkOption[] noFollowLinkOptionArray()
Copy of theLinkOptionarray forLinkOption.NOFOLLOW_LINKS.- Returns:
 - Copy of the 
LinkOptionarray forLinkOption.NOFOLLOW_LINKS. 
 
- 
readAttributes
public static <A extends java.nio.file.attribute.BasicFileAttributes> A readAttributes(java.nio.file.Path path, java.lang.Class<A> type, java.nio.file.LinkOption... options)Reads the BasicFileAttributes from the given path. Returns null if the attributes can't be read.- Type Parameters:
 A- TheBasicFileAttributestype- Parameters:
 path- The Path to test.type- theClassof the file attributes required to read.options- options indicating how to handle symbolic links.- Returns:
 - the file attributes or null if the attributes can't be read.
 - Since:
 - 2.12.0
 - See Also:
 Files.readAttributes(Path, Class, LinkOption...)
 
- 
readBasicFileAttributes
public static java.nio.file.attribute.BasicFileAttributes readBasicFileAttributes(java.nio.file.Path path) throws java.io.IOExceptionReads the BasicFileAttributes from the given path.- Parameters:
 path- the path to read.- Returns:
 - the path attributes.
 - Throws:
 java.io.IOException- if an I/O error occurs.- Since:
 - 2.9.0
 
 
- 
readBasicFileAttributes
public static java.nio.file.attribute.BasicFileAttributes readBasicFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the BasicFileAttributes from the given path. Returns null if the attributes can't be read.- Parameters:
 path- the path to read.options- options indicating how to handle symbolic links.- Returns:
 - the path attributes.
 - Since:
 - 2.12.0
 
 
- 
readBasicFileAttributesUnchecked
@Deprecated public static java.nio.file.attribute.BasicFileAttributes readBasicFileAttributesUnchecked(java.nio.file.Path path)
Deprecated.Reads the BasicFileAttributes from the given path. Returns null if the attributes can't be read.- Parameters:
 path- the path to read.- Returns:
 - the path attributes.
 - Since:
 - 2.9.0
 
 
- 
readDosFileAttributes
public static java.nio.file.attribute.DosFileAttributes readDosFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the DosFileAttributes from the given path. Returns null if the attributes can't be read.- Parameters:
 path- the path to read.options- options indicating how to handle symbolic links.- Returns:
 - the path attributes.
 - Since:
 - 2.12.0
 
 
- 
readOsFileAttributes
public static java.nio.file.attribute.BasicFileAttributes readOsFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the PosixFileAttributes or DosFileAttributes from the given path. Returns null if the attributes can't be read.- Parameters:
 path- The Path to read.options- options indicating how to handle symbolic links.- Returns:
 - the file attributes.
 - Since:
 - 2.12.0
 
 
- 
readPosixFileAttributes
public static java.nio.file.attribute.PosixFileAttributes readPosixFileAttributes(java.nio.file.Path path, java.nio.file.LinkOption... options)Reads the PosixFileAttributes from the given path. Returns null instead of throwingUnsupportedOperationException.- Parameters:
 path- The Path to read.options- options indicating how to handle symbolic links.- Returns:
 - the file attributes.
 - Since:
 - 2.12.0
 
 
- 
readString
public static java.lang.String readString(java.nio.file.Path path, java.nio.charset.Charset charset) throws java.io.IOExceptionReads the given path as a String.- Parameters:
 path- The source path.charset- How to convert bytes to a String, null uses the default Charset.- Returns:
 - a new String.
 - Throws:
 java.io.IOException- if an I/O error occurs reading from the stream.- Since:
 - 2.12.0
 - See Also:
 Files.readAllBytes(Path)
 
- 
setLastModifiedTime
public static void setLastModifiedTime(java.nio.file.Path sourceFile, java.nio.file.Path targetFile) throws java.io.IOExceptionSets the giventargetFile's last modified time to the value fromsourceFile.- Parameters:
 sourceFile- The source path to query.targetFile- The target path to set.- Throws:
 java.lang.NullPointerException- if sourceFile isnull.java.lang.NullPointerException- if targetFile isnull.java.io.IOException- if setting the last-modified time failed.- Since:
 - 2.12.0
 
 
- 
setReadOnly
public static java.nio.file.Path setReadOnly(java.nio.file.Path path, boolean readOnly, java.nio.file.LinkOption... linkOptions) throws java.io.IOExceptionSets the given Path to thereadOnlyvalue.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 to handle symbolic links.- Returns:
 - The given path.
 - Throws:
 java.io.IOException- if an I/O error occurs.- Since:
 - 2.8.0
 
 
- 
sizeOf
public static long sizeOf(java.nio.file.Path path) throws java.io.IOExceptionReturns the size of the given file or directory. If the providedPathis a regular file, then the file's size is returned. If the argument is a directory, then the size of the directory is calculated recursively.Note that overflow is not detected, and the return value may be negative if overflow occurs. See
sizeOfAsBigInteger(Path)for an alternative method that does not overflow.- Parameters:
 path- the regular file or directory to return the size of, must not benull.- Returns:
 - the length of the file, or recursive size of the directory, in bytes.
 - Throws:
 java.lang.NullPointerException- if the file isnull.java.lang.IllegalArgumentException- if the file does not exist.java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
sizeOfAsBigInteger
public static java.math.BigInteger sizeOfAsBigInteger(java.nio.file.Path path) throws java.io.IOExceptionReturns the size of the given file or directory. If the providedPathis a regular file, then the file's size is returned. If the argument is a directory, then the size of the directory is calculated recursively.- Parameters:
 path- the regular file or directory to return the size of (must not benull).- Returns:
 - the length of the file, or recursive size of the directory, provided (in bytes).
 - Throws:
 java.lang.NullPointerException- if the file isnull.java.lang.IllegalArgumentException- if the file does not exist.java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
sizeOfDirectory
public static long sizeOfDirectory(java.nio.file.Path directory) throws java.io.IOExceptionCounts the size of a directory recursively (sum of the size of all files).Note that overflow is not detected, and the return value may be negative if overflow occurs. See
sizeOfDirectoryAsBigInteger(Path)for an alternative method that does not overflow.- Parameters:
 directory- directory to inspect, must not benull.- Returns:
 - size of directory in bytes, 0 if directory is security restricted, a negative number when the real total is greater than 
Long.MAX_VALUE. - Throws:
 java.lang.NullPointerException- if the directory isnull.java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
sizeOfDirectoryAsBigInteger
public static java.math.BigInteger sizeOfDirectoryAsBigInteger(java.nio.file.Path directory) throws java.io.IOExceptionCounts the size of a directory recursively (sum of the size of all files).- Parameters:
 directory- directory to inspect, must not benull.- Returns:
 - size of directory in bytes, 0 if directory is security restricted.
 - Throws:
 java.lang.NullPointerException- if the directory isnull.java.io.IOException- if an I/O error occurs.- Since:
 - 2.12.0
 
 
- 
touch
public static java.nio.file.Path touch(java.nio.file.Path file) throws java.io.IOExceptionImplements behavior similar to the UNIX "touch" utility. Creates a new file with size 0, or, if the file exists, just updates the file's modified time. this method creates parent directories if they do not exist.- Parameters:
 file- the file to touch.- Returns:
 - The given file.
 - Throws:
 java.lang.NullPointerException- if the parameter isnull.java.io.IOException- if setting the last-modified time failed or an I/O problem occurs.\- Since:
 - 2.12.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.IOExceptionPerformsFiles.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:
 java.nio.file.NoSuchFileException- if the directory does not exist.java.io.IOException- if an I/O error is thrown by a visitor method.java.lang.NullPointerException- if the directory isnull.
 
- 
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.IOExceptionPerformsFiles.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:
 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.IOExceptionPerformsFiles.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:
 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.IOExceptionPerformsFiles.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:
 java.io.IOException- if an I/O error is thrown by a visitor method.
 
- 
waitFor
public static boolean waitFor(java.nio.file.Path file, java.time.Duration timeout, java.nio.file.LinkOption... options)Waits for the file system to propagate a file creation, with a timeout.This method repeatedly tests
Files.exists(Path,LinkOption...)until it returns true up to the maximum time given.- Parameters:
 file- the file to check, must not benull.timeout- the maximum time to wait.options- options indicating how to handle symbolic links.- Returns:
 - true if file exists.
 - Throws:
 java.lang.NullPointerException- if the file isnull.- Since:
 - 2.12.0
 
 
- 
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.IOExceptionReturns a stream of filtered paths.The returned
Streammay wrap one or moreDirectoryStreams. When you require timely disposal of file system resources, use atry-with-resources block to ensure invocation of the stream'sBaseStream.close()method after the stream operations are completed. Calling a closed stream causes aIllegalStateException.- 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:
 java.io.IOException- if an I/O error is thrown when accessing the starting file.- Since:
 - 2.9.0
 
 
- 
writeString
public static java.nio.file.Path writeString(java.nio.file.Path path, java.lang.CharSequence charSequence, java.nio.charset.Charset charset, java.nio.file.OpenOption... openOptions) throws java.io.IOExceptionWrites the given character sequence to a file at the given path.- Parameters:
 path- The target file.charSequence- The character sequence text.charset- The Charset to encode the text.openOptions- options How to open the file.- Returns:
 - The given path.
 - Throws:
 java.io.IOException- if an I/O error occurs writing to or creating the file.java.lang.NullPointerException- if eitherpathorcharSequenceisnull.- Since:
 - 2.12.0
 
 
 - 
 
 -