Class FileUtils


  • public class FileUtils
    extends Object
    • Method Detail

      • moveFileWithOverwrite

        public static void moveFileWithOverwrite​(File srcFile,
                                                 File destFile)
                                          throws IOException
        Deletes the destination file if it exists then calls org.apache.commons moveFile.
        Parameters:
        srcFile -
        destFile -
        Throws:
        IOException
      • transferBytes

        public static void transferBytes​(FileChannel src,
                                         long position,
                                         long count,
                                         FileChannel dest)
                                  throws IOException
        Transfers bytes from the source file to the destination file. This method can handle transfer size larger than 2G.
        Parameters:
        src - Source file channel
        position - Position in source file
        count - Number of bytes to transfer
        dest - Destination file channel
        Throws:
        IOException
      • close

        public static void close​(Iterable<? extends Closeable> closeables)
                          throws IOException
        Close a collection of Closeable resources This is a utility method to help release multiple Closeable resources in a safe manner without leaking. As an example if we have a list of Closeable resources, then the following code is prone to leaking 1 or more subsequent resources if an exception is thrown while closing one of them. for (closeable_resource : resources) { closeable_resource.close() } The helper methods provided here do this safely while keeping track of exception(s) raised during close() of each resource and still continuing to close subsequent resources.
        Parameters:
        closeables - collection of resources to close
        Throws:
        IOException
      • close

        public static void close​(Closeable... closeables)
                          throws IOException
        Another version of close(Iterable) which allows to pass variable number of closeable resources when the caller doesn't already have them in a collection.
        Parameters:
        closeables - one or more resources to close
        Throws:
        IOException