Top Description Constructors Methods
org.springframework.util

public abstract Class FileSystemUtils

extends Object
Class Inheritance
Imports
java.io.File, .IOException, java.nio.file.FileVisitResult, .Files, .Path, .SimpleFileVisitor, .StandardCopyOption, java.nio.file.attribute.BasicFileAttributes, java.util.EnumSet, org.springframework.lang.Nullable

Utility methods for working with the file system.
Authors
Rob Harrop, Juergen Hoeller
Since
2.5.3
See Also
java.io.File, java.nio.file.Path, java.nio.file.Files

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
copyRecursively(File
the source directory
src
,
File
the destination directory
dest
)

Recursively copy the contents of the src file/directory to the dest file/directory.

public static void
copyRecursively(Path
the source directory
src
,
Path
the destination directory
dest
)

Recursively copy the contents of the src file/directory to the dest file/directory.

public static boolean

Returns:

true if the File was successfully deleted, otherwise false
deleteRecursively
(File
the root File to delete
root
)

Delete the supplied File - for directories, recursively delete any nested directories or files as well.

public static boolean

Returns:

true if the Path existed and was deleted, or false if it did not exist
deleteRecursively
(Path
the root Path to delete
root
)

Delete the supplied Path — for directories, recursively delete any nested directories or files as well.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FileSystemUtilsback to summary
public FileSystemUtils()

Method Detail

copyRecursivelyback to summary
public static void copyRecursively(File src, File dest) throws IOException

Recursively copy the contents of the src file/directory to the dest file/directory.

Parameters
src:File

the source directory

dest:File

the destination directory

Exceptions
IOException:
in the case of I/O errors
copyRecursivelyback to summary
public static void copyRecursively(Path src, Path dest) throws IOException

Recursively copy the contents of the src file/directory to the dest file/directory.

Parameters
src:Path

the source directory

dest:Path

the destination directory

Exceptions
IOException:
in the case of I/O errors
Since
5.0
deleteRecursivelyback to summary
public static boolean deleteRecursively(File root)

Delete the supplied File - 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 returns false in case of I/O errors. Consider using deleteRecursively(Path) for NIO-style handling of I/O errors, clearly differentiating between non-existence and failure to delete an existing file.

Parameters
root:File

the root File to delete

Returns:boolean

true if the File was successfully deleted, otherwise false

deleteRecursivelyback to summary
public static boolean deleteRecursively(Path root) throws IOException

Delete the supplied Path — for directories, recursively delete any nested directories or files as well.

Parameters
root:Path

the root Path to delete

Returns:boolean

true if the Path existed and was deleted, or false if it did not exist

Exceptions
IOException:
in the case of I/O errors
Since
5.0