Files.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanRecursively(Path path) Attempt to recursively clean the file or directory at the given path.static voidAttempt to recursively clean all of the files returned by the given directory stream.static voidcleanRecursively(SecureDirectoryStream<Path> sds, Path path) Attempt to recursively clean the file or directory at the given directory and path.static voidAttempt to recursively clean all of the files and directories from the given stream, even if secure directory streams are not supported.static voidAttempt to recursively clean the file or directory at the given path, even if secure directory streams are not supported.static PathReturns the current working directory path at the time that this program was started (notnull).static voiddeleteRecursively(Path path) Attempt to recursively delete the file or directory at the given path.static voidAttempt to recursively delete all of the files returned by the given directory stream.static voiddeleteRecursively(SecureDirectoryStream<Path> sds, Path path) Attempt to recursively delete the file or directory at the given directory and path.static voidAttempt to recursively delete all of the files returned by the given directory stream, even if secure directory streams are not supported.static voidAttempt to recursively delete the file or directory at the given path, even if secure directory streams are not supported.static DeleteStatsdeleteRecursivelyQuietly(Path path) Attempt to recursively delete the file or directory at the given path.static DeleteStatsAttempt to recursively delete all of the files returned by the given directory stream.static DeleteStatsdeleteRecursivelyQuietly(SecureDirectoryStream<Path> sds, Path path) Attempt to recursively delete the file or directory at the given directory and path.static DeleteStatsAttempt to recursively delete all of the files returned by the given directory stream, even if secure directory streams are not supported.static DeleteStatsAttempt to recursively delete the file or directory at the given path, even if secure directory streams are not supported.static PathReturns the parent of the given path, even if it is relative, ornullif the path has no parent.static booleanReturnstrueif this platform has secure directories, orfalseif it does not.static SecureDirectoryStream<Path> newSecureDirectoryStream(Path path, LinkOption... linkOptions) Open a new secure directory stream at the given path.
-
Method Details
-
newSecureDirectoryStream
public static SecureDirectoryStream<Path> newSecureDirectoryStream(Path path, LinkOption... linkOptions) throws IOException Open a new secure directory stream at the given path. If the link optionLinkOption.NOFOLLOW_LINKSis given, the open will fail with an exception ifpathis a symbolic link.- Parameters:
path- the path of the directory to open (must not benull)linkOptions- the link options (must not benull)- Returns:
- a secure directory stream for the given path (not
null) - Throws:
NotDirectoryException- if the targetpathis not a directoryIOException- if another I/O error occursUnsupportedOperationException- if this platform does not support secure directory streams- See Also:
-
deleteRecursivelyEvenIfInsecure
Attempt to recursively delete the file or directory at the given path, even if secure directory streams are not supported. If the target path is a symbolic link, it will be removed. Warning: this method can potentially delete files outside the intended path if the target platform does not support secure directory iteration.- Parameters:
path- the path to delete (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occurs- See Also:
-
deleteRecursivelyEvenIfInsecure
Attempt to recursively delete all of the files returned by the given directory stream, even if secure directory streams are not supported. If any of the target paths are symbolic links, they will be removed. Warning: this method can potentially delete files outside the intended path if the target platform does not support secure directory iteration.The directory stream is not closed by this operation. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
ds- the directory stream whose contents should be removed (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occurs- See Also:
-
deleteRecursively
Attempt to recursively delete the file or directory at the given path. If the target path is a symbolic link, it will be removed.- Parameters:
path- the file or directory to be removed (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occursUnsupportedOperationException- if secure directory removal is unsupported
-
deleteRecursively
Attempt to recursively delete all of the files returned by the given directory stream. If any of the target paths are symbolic links, they will be removed.The directory stream is not closed by this operation, but its iterator is consumed. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
sds- the directory stream whose contents should be removed (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occurs
-
deleteRecursively
Attempt to recursively delete the file or directory at the given directory and path. If the target path or any nested path is a symbolic link, it will be removed and will not be treated as a directory. If the target path is absolute, thensdsis ignored and the absolute path is removed. The caller should ensure that the given path is sanitized if needed (seePath.normalize()andPath.isAbsolute()).The directory stream is not closed by this operation, and its iterator is not consumed. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
sds- the directory stream containing the file (must not benull)path- the relative path of the file or directory to be removed (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occurs
-
deleteRecursivelyQuietlyEvenIfInsecure
Attempt to recursively delete the file or directory at the given path, even if secure directory streams are not supported. I/O errors will not be reported. If the target path is a symbolic link, it will be removed. Warning: this method can potentially delete files outside the intended path if the target platform does not support secure directory iteration.- Parameters:
path- the path to delete (must not benull)- Returns:
- the deletion statistics (not
null) - See Also:
-
deleteRecursivelyQuietlyEvenIfInsecure
Attempt to recursively delete all of the files returned by the given directory stream, even if secure directory streams are not supported. I/O errors will not be reported. If any of the target paths are symbolic links, they will be removed. Warning: this method can potentially delete files outside the intended path if the target platform does not support secure directory iteration.The directory stream is not closed by this operation. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
ds- the directory stream whose contents should be removed (must not benull)- Returns:
- the deletion statistics (not
null) - See Also:
-
deleteRecursivelyQuietly
Attempt to recursively delete the file or directory at the given path. If the target path is a symbolic link, it will be removed. I/O errors will not be reported.- Parameters:
path- the file or directory to be removed (must not benull)- Returns:
- the deletion statistics (not
null) - Throws:
UnsupportedOperationException- if secure directory removal is unsupported
-
deleteRecursivelyQuietly
Attempt to recursively delete all of the files returned by the given directory stream. If any of the target paths are symbolic links, they will be removed. I/O errors will not be reported.The directory stream is not closed by this operation, but its iterator is consumed. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
sds- the directory stream whose contents should be removed (must not benull)- Returns:
- the deletion statistics (not
null)
-
deleteRecursivelyQuietly
Attempt to recursively delete the file or directory at the given directory and path. If the target path or any nested path is a symbolic link, it will be removed and will not be treated as a directory. If the target path is absolute, thensdsis ignored and the absolute path is removed. I/O errors will not be reported. The caller should ensure that the given path is sanitized if needed (seePath.normalize()andPath.isAbsolute()).The directory stream is not closed by this operation, and its iterator is not consumed. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
sds- the directory stream containing the file (must not benull)path- the relative path of the file or directory to be removed (must not benull)- Returns:
- the deletion statistics (not
null)
-
cleanRecursivelyEvenIfInsecure
Attempt to recursively clean the file or directory at the given path, even if secure directory streams are not supported. If the target path or any nested path is not a directory, it will be removed. Directories will be preserved. Warning: this method can potentially delete files outside the intended path if the target platform does not support secure directory iteration.- Parameters:
path- the path to clean (must not benull)- Throws:
IOException- if one or more files fails to be cleaned or another I/O error occurs- See Also:
-
cleanRecursivelyEvenIfInsecure
Attempt to recursively clean all of the files and directories from the given stream, even if secure directory streams are not supported. If any nested path is not a directory, it will be removed. Directories will be preserved. Warning: this method can potentially delete files outside the intended path if the target platform does not support secure directory iteration.The directory stream is not closed by this operation. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
ds- the directory stream whose contents should be cleaned (must not benull)- Throws:
IOException- if one or more files fails to be cleaned or another I/O error occurs- See Also:
-
cleanRecursively
Attempt to recursively clean the file or directory at the given path. If the target path is not a directory, it will be removed.- Parameters:
path- the file or directory to be cleaned (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occursUnsupportedOperationException- if secure directory traversal is unsupported
-
cleanRecursively
Attempt to recursively clean all of the files returned by the given directory stream. If any of the target paths are not directories, they will be removed.The directory stream is not closed by this operation, but its iterator is consumed. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
sds- the directory stream whose contents should be cleaned (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occurs
-
cleanRecursively
Attempt to recursively clean the file or directory at the given directory and path. If the target path or any nested path is a symbolic link, it will be removed and will not be treated as a directory. If any of the target paths are not directories, they will be removed. If the target path is absolute, thensdsis ignored and the absolute path is cleaned. The caller should ensure that the given path is sanitized if needed (seePath.normalize()andPath.isAbsolute()).The directory stream is not closed by this operation, and its iterator is not consumed. The caller should ensure that the stream is closed at the appropriate time.
- Parameters:
sds- the directory stream containing the file (must not benull)path- the relative path of the file or directory to be cleaned (must not benull)- Throws:
IOException- if one or more files fails to be deleted or another I/O error occurs
-
getParent
Returns the parent of the given path, even if it is relative, ornullif the path has no parent. Relative paths are resolved relative to the current directory.- Parameters:
path- the path to examine (must not benull)- Returns:
- the parent of the given path, even if it is relative, or
nullif the path has no parent - See Also:
-
currentDirectory
Returns the current working directory path at the time that this program was started (notnull). This path comes from theuser.dirsystem property.- Returns:
- the current working directory path at the time that this program was started (not
null)
-
hasSecureDirectories
public static boolean hasSecureDirectories()Returnstrueif this platform has secure directories, orfalseif it does not. Some operating systems or JVM versions do not support secure directories.- Returns:
trueif this platform has secure directories, orfalseif it does not
-