Package org.springframework.util
Class FileSystemUtils
- java.lang.Object
- org.springframework.util.FileSystemUtils
public abstract class FileSystemUtils extends Object
Utility methods for working with the file system.
Constructor Summary
Constructors Constructor Description FileSystemUtils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyRecursively(File src, File dest)Recursively copy the contents of thesrcfile/directory to thedestfile/directory.static voidcopyRecursively(Path src, Path dest)Recursively copy the contents of thesrcfile/directory to thedestfile/directory.static booleandeleteRecursively(File root)Delete the suppliedFile- for directories, recursively delete any nested directories or files as well.static booleandeleteRecursively(Path root)Delete the suppliedFile— for directories, recursively delete any nested directories or files as well.
Constructor Detail
FileSystemUtils
public FileSystemUtils()
Method Detail
deleteRecursively
public static boolean deleteRecursively(@Nullable File root)
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 returnsfalsein 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 rootFileto delete- Returns:
trueif theFilewas successfully deleted, otherwisefalse
deleteRecursively
public static boolean deleteRecursively(@Nullable Path root) throws IOException
Delete the suppliedFile— for directories, recursively delete any nested directories or files as well.- Parameters:
root- the rootFileto delete- Returns:
trueif theFileexisted and was deleted, orfalseif it did not exist- Throws:
IOException- in the case of I/O errors- Since:
- 5.0
copyRecursively
public static void copyRecursively(File src, File dest) throws IOException
Recursively copy the contents of thesrcfile/directory to thedestfile/directory.- Parameters:
src- the source directorydest- the destination directory- Throws:
IOException- in the case of I/O errors
copyRecursively
public static void copyRecursively(Path src, Path dest) throws IOException
Recursively copy the contents of thesrcfile/directory to thedestfile/directory.- Parameters:
src- the source directorydest- the destination directory- Throws:
IOException- in the case of I/O errors- Since:
- 5.0