org.springframework.util

Class FileSystemUtils

  • java.lang.Object
    • org.springframework.util.FileSystemUtils


  • public abstract class FileSystemUtils
    extends java.lang.Object
    Utility methods for working with the file system.
    Since:
    2.5.3
    Author:
    Rob Harrop, Juergen Hoeller
    See Also:
    File, Path, Files
    • Constructor Summary

      Constructors 
      Constructor and Description
      FileSystemUtils() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void copyRecursively(java.io.File src, java.io.File dest)
      Recursively copy the contents of the src file/directory to the dest file/directory.
      static void copyRecursively(java.nio.file.Path src, java.nio.file.Path dest)
      Recursively copy the contents of the src file/directory to the dest file/directory.
      static boolean deleteRecursively(java.io.File root)
      Delete the supplied File - for directories, recursively delete any nested directories or files as well.
      static boolean deleteRecursively(java.nio.file.Path root)
      Delete the supplied File - for directories, recursively delete any nested directories or files as well.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileSystemUtils

        public FileSystemUtils()
    • Method Detail

      • deleteRecursively

        public static boolean deleteRecursively(@Nullable
                                                java.io.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 - the root File to delete
        Returns:
        true if the File was successfully deleted, otherwise false
      • deleteRecursively

        public static boolean deleteRecursively(@Nullable
                                                java.nio.file.Path root)
                                         throws java.io.IOException
        Delete the supplied File - for directories, recursively delete any nested directories or files as well.
        Parameters:
        root - the root File to delete
        Returns:
        true if the File existed and was deleted, or false it it did not exist
        Throws:
        java.io.IOException - in the case of I/O errors
        Since:
        5.0
      • copyRecursively

        public static void copyRecursively(java.io.File src,
                                           java.io.File dest)
                                    throws java.io.IOException
        Recursively copy the contents of the src file/directory to the dest file/directory.
        Parameters:
        src - the source directory
        dest - the destination directory
        Throws:
        java.io.IOException - in the case of I/O errors
      • copyRecursively

        public static void copyRecursively(java.nio.file.Path src,
                                           java.nio.file.Path dest)
                                    throws java.io.IOException
        Recursively copy the contents of the src file/directory to the dest file/directory.
        Parameters:
        src - the source directory
        dest - the destination directory
        Throws:
        java.io.IOException - in the case of I/O errors
        Since:
        5.0