Package org.springframework.util
Class FileSystemUtils
java.lang.Object
org.springframework.util.FileSystemUtils
Utility methods for working with the file system.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
copyRecursively
(File src, File dest) Recursively copy the contents of thesrc
file/directory to thedest
file/directory.static void
copyRecursively
(Path src, Path dest) Recursively copy the contents of thesrc
file/directory to thedest
file/directory.static boolean
deleteRecursively
(File root) Delete the suppliedFile
- for directories, recursively delete any nested directories or files as well.static boolean
deleteRecursively
(Path root) Delete the suppliedFile
— for directories, recursively delete any nested directories or files as well.
-
Constructor Details
-
FileSystemUtils
public FileSystemUtils()
-
-
Method Details
-
deleteRecursively
Delete the suppliedFile
- for directories, recursively delete any nested directories or files as well.Note: Like
File.delete()
, this method does not throw any exception but rather silently returnsfalse
in case of I/O errors. Consider usingdeleteRecursively(Path)
for NIO-style handling of I/O errors, clearly differentiating between non-existence and failure to delete an existing file.- Parameters:
root
- the rootFile
to delete- Returns:
true
if theFile
was successfully deleted, otherwisefalse
-
deleteRecursively
Delete the suppliedFile
— for directories, recursively delete any nested directories or files as well.- Parameters:
root
- the rootFile
to delete- Returns:
true
if theFile
existed and was deleted, orfalse
if it did not exist- Throws:
IOException
- in the case of I/O errors- Since:
- 5.0
-
copyRecursively
Recursively copy the contents of thesrc
file/directory to thedest
file/directory.- Parameters:
src
- the source directorydest
- the destination directory- Throws:
IOException
- in the case of I/O errors
-
copyRecursively
Recursively copy the contents of thesrc
file/directory to thedest
file/directory.- Parameters:
src
- the source directorydest
- the destination directory- Throws:
IOException
- in the case of I/O errors- Since:
- 5.0
-