Class FileUtils


  • public final class FileUtils
    extends Object
    Simple utility methods for dealing with files and directories.
    Since:
    4.0.0
    Author:
    Dmytro Nosan
    • Method Detail

      • delete

        public static boolean delete​(Path path)
                              throws IOException
        Deletes the supplied Path. For directories, recursively delete any nested directories or files as well.
        Parameters:
        path - the path to delete
        Returns:
        true if the path existed and was deleted, or false it did not exist
        Throws:
        IOException - in the case of I/O errors
      • copy

        public static void copy​(Path src,
                                Path dest,
                                CopyOption... options)
                         throws IOException
        Copies a path to a target path. For directories, it will be copied recursively.
        Parameters:
        src - the source path
        dest - the destination path
        options - specifying how the copy should be done the path to the target file
        Throws:
        IOException - in the case of I/O errors
      • copy

        public static void copy​(Path src,
                                Path dest,
                                BiPredicate<? super Path,​? super BasicFileAttributes> filter,
                                CopyOption... options)
                         throws IOException
        Copies a path to a target path. For directories, it will be copied recursively.
        Parameters:
        src - the source path
        dest - the destination path
        options - specifying how the copy should be done the path to the target file
        filter - the function used to decide whether a path should be copied or not
        Throws:
        IOException - in the case of I/O errors
      • checksum

        public static String checksum​(Path file,
                                      String algorithm)
                               throws NoSuchAlgorithmException,
                                      IOException
        Computes the checksum of the file using the provided algorithm.
        Parameters:
        file - the file to read
        algorithm - the name of the algorithm.
        Returns:
        the computed checksum in lowercase hex format
        Throws:
        NoSuchAlgorithmException - if no Provider supports a MessageDigestSpi implementation for the specified algorithm.
        IOException - in the case of I/O errors